This module exposes helper functions for encoding sum types and maps. It was designed
with an eye for compatibility with the aeson library from the Haskell world, which explains
why the various functions have such peculiar names.
If you require Haskell interop, please take a look at the elm-bridge package that will make it easy to derive the Elm code alongside the Haskell one.
Creates an ObjectEncoding, just like the Json.Encode.object function.
Creates an ObjectEncoding from any type of Value. You should not use this for Values that are actually objects.
The following Elm type will be used as an example for the different encoding schemes.
type Foo = Bar Int
| Baz { a: Int , b: Int }
| Qux Int Int-- {"Bar":5}
-- {"Baz":{"a":4,"b":8}}
-- {"Qux":[98,42]}Decode objects encoded using the ObjectWithSingleField scheme.
The first argument is the human readable name of the type of data, and will be used in error messages.
The second argument is a Dict where the keys are the tags of each constructor of the sum type and the values
are decoders for each case.
Encode objects using the WithSingleField scheme.
The first argument is a function that, for each possible value a, must return a String tag
describing it along with an ObjectEncoding.
-- ["Bar",5]
-- ["Baz",{"a":4,"b":8}]
-- ["Qux",[98,42]]Decode objects encoded using the TwoElemArray scheme.
The first argument is the human readable name of the type of data, and will be used in error messages.
The second argument is a Dict where the keys are the tags of each constructor of the sum type and the values
are decoders for each case.
Encode objects using the TwoElementArray scheme.
The first argument is a function that, for each possible value a, must return a String tag
describing it along with an ObjectEncoding.
-- {"tag":"Bar","content":5}
-- {"tag":"Baz","a":4,"b":8}
-- ["tag":"Qux","content":[98,42]}Decode objects encoded using the TaggedObject scheme.
The first argument is the human readable name of the type of data, and will be used in error messages.
The second argument is a Dict where the keys are the tags of each constructor of the sum type and the values
are decoders for each case.
Compared to the other functions, it expects a set of Strings. This sets lists all the constructor tags that have an object content,
such as the Baz constructor in the example.
Encode objects using the TaggedObject scheme.
The first argument is a function that, for each possible value a, must return a String tag
describing it along with an ObjectEncoding.
Helper for decoding enum-like sum types
Helper function for decoding map-like objects. It takes a decoder for the key type and a decoder for the value type.
Helper function for encoding map-like objects. It takes an encoder for the key type and an encoder for the value type
An alias to encodeMap that is compatible with the naming convention from elm-bridge
An alias to decodeMap that is compatible with the naming convention from elm-bridge
A helper for set encoding
A helper for set decoding
Encodes an optional value, using null when there is Nothing
The bind operator, which works like the old `andThen
This is the old operator from Elm 0.17
This is an opaque type that is to be used to give hints when using the
TaggedObjectencoding.