A Decoder
describes how to attempt to decode some input of type i
(an
entity or an attribute) and produce some output of type a
.
Represents an entire STEP file composed of a header and a list of entities. You can get the header from a file or extract data from it using entity decoders.
Represents a 'context' value that is threaded through decoding after being passed in at the top level (and possibly updated/transformed during decoding).
parse : String -> Result String File
Attempt to parse a given string as a STEP file.
header : File -> Step.Types.Header
Get the header of a given file.
single : Decoder Step.Types.Entity context output -> File -> context -> Result String output
Attempt to find exactly one entity in a file that matches the given decoder. If there are no matching entities or more than one matching entity, an error message will be returned.
all : Decoder Step.Types.Entity context output -> File -> context -> Result String (List output)
Find all entities in a file matching the given decoder.
get : Basics.Int -> Decoder Step.Types.Entity context output -> File -> context -> Result String output
Decode a single entity from a file by ID, using the given decoder. Usually
you will want to use single
instead.
The simpleEntity*
functions all attempt to decode a simple STEP entity with
the given number of attributes.
simpleEntity1 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> output) -> Decoder Step.Types.Entity context output
simpleEntity2 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> output) -> Decoder Step.Types.Entity context output
simpleEntity3 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> output) -> Decoder Step.Types.Entity context output
simpleEntity4 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> output) -> Decoder Step.Types.Entity context output
simpleEntity5 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> output) -> Decoder Step.Types.Entity context output
simpleEntity6 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> output) -> Decoder Step.Types.Entity context output
simpleEntity7 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> output) -> Decoder Step.Types.Entity context output
simpleEntity8 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> output) -> Decoder Step.Types.Entity context output
simpleEntity9 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> output) -> Decoder Step.Types.Entity context output
simpleEntity10 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> output) -> Decoder Step.Types.Entity context output
simpleEntity11 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> output) -> Decoder Step.Types.Entity context output
simpleEntity12 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.Attribute context (m -> output) -> Decoder Step.Types.Entity context output
simpleEntity13 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.Attribute context (m -> n) -> Decoder Step.Types.Attribute context (n -> output) -> Decoder Step.Types.Entity context output
simpleEntity14 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.Attribute context (m -> n) -> Decoder Step.Types.Attribute context (n -> o) -> Decoder Step.Types.Attribute context (o -> output) -> Decoder Step.Types.Entity context output
simpleEntity15 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.Attribute context (m -> n) -> Decoder Step.Types.Attribute context (n -> o) -> Decoder Step.Types.Attribute context (o -> p) -> Decoder Step.Types.Attribute context (p -> output) -> Decoder Step.Types.Entity context output
simpleEntity16 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> String -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.Attribute context (m -> n) -> Decoder Step.Types.Attribute context (n -> o) -> Decoder Step.Types.Attribute context (o -> p) -> Decoder Step.Types.Attribute context (p -> q) -> Decoder Step.Types.Attribute context (q -> output) -> Decoder Step.Types.Entity context output
The complexEntity*
functions all attempt to decode a complex STEP entity with
the given number of sub-entities.
complexEntity1 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> output) -> Decoder Step.Types.Entity context output
complexEntity2 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> output) -> Decoder Step.Types.Entity context output
complexEntity3 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> output) -> Decoder Step.Types.Entity context output
complexEntity4 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> output) -> Decoder Step.Types.Entity context output
complexEntity5 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> output) -> Decoder Step.Types.Entity context output
complexEntity6 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> output) -> Decoder Step.Types.Entity context output
complexEntity7 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> h) -> Decoder Step.Types.SubEntity context (h -> output) -> Decoder Step.Types.Entity context output
complexEntity8 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> h) -> Decoder Step.Types.SubEntity context (h -> i) -> Decoder Step.Types.SubEntity context (i -> output) -> Decoder Step.Types.Entity context output
complexEntity9 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> h) -> Decoder Step.Types.SubEntity context (h -> i) -> Decoder Step.Types.SubEntity context (i -> j) -> Decoder Step.Types.SubEntity context (j -> output) -> Decoder Step.Types.Entity context output
complexEntity10 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> h) -> Decoder Step.Types.SubEntity context (h -> i) -> Decoder Step.Types.SubEntity context (i -> j) -> Decoder Step.Types.SubEntity context (j -> k) -> Decoder Step.Types.SubEntity context (k -> output) -> Decoder Step.Types.Entity context output
complexEntity11 : callback -> Decoder Context context (callback -> a) -> Decoder Basics.Int context (a -> b) -> Decoder Step.Types.SubEntity context (b -> c) -> Decoder Step.Types.SubEntity context (c -> d) -> Decoder Step.Types.SubEntity context (d -> e) -> Decoder Step.Types.SubEntity context (e -> f) -> Decoder Step.Types.SubEntity context (f -> g) -> Decoder Step.Types.SubEntity context (g -> h) -> Decoder Step.Types.SubEntity context (h -> i) -> Decoder Step.Types.SubEntity context (i -> j) -> Decoder Step.Types.SubEntity context (j -> k) -> Decoder Step.Types.SubEntity context (k -> l) -> Decoder Step.Types.SubEntity context (l -> output) -> Decoder Step.Types.Entity context output
subEntity0 : String -> Decoder Step.Types.SubEntity context (a -> a)
subEntity1 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.SubEntity context (a -> b)
subEntity2 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.SubEntity context (a -> c)
subEntity3 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.SubEntity context (a -> d)
subEntity4 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.SubEntity context (a -> e)
subEntity5 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.SubEntity context (a -> f)
subEntity6 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.SubEntity context (a -> g)
subEntity7 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.SubEntity context (a -> h)
subEntity8 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.SubEntity context (a -> i)
subEntity9 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.SubEntity context (a -> j)
subEntity10 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.SubEntity context (a -> k)
subEntity11 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.SubEntity context (a -> l)
subEntity12 : String -> Decoder Step.Types.Attribute context (a -> b) -> Decoder Step.Types.Attribute context (b -> c) -> Decoder Step.Types.Attribute context (c -> d) -> Decoder Step.Types.Attribute context (d -> e) -> Decoder Step.Types.Attribute context (e -> f) -> Decoder Step.Types.Attribute context (f -> g) -> Decoder Step.Types.Attribute context (g -> h) -> Decoder Step.Types.Attribute context (h -> i) -> Decoder Step.Types.Attribute context (i -> j) -> Decoder Step.Types.Attribute context (j -> k) -> Decoder Step.Types.Attribute context (k -> l) -> Decoder Step.Types.Attribute context (l -> m) -> Decoder Step.Types.SubEntity context (a -> m)
oneOf : List (Decoder Step.Types.Entity context a) -> Decoder Step.Types.Entity context a
Construct an entity decoder that tries several other entity decoders in sequence.
keepContext : Decoder Context context ((context -> a) -> a)
Get the current context while decoding.
ignoreContext : Decoder Context context (a -> a)
Ignore the current context while decoding.
keepId : Decoder Basics.Int context ((Basics.Int -> a) -> a)
Get the ID of an entity while decoding.
ignoreId : Decoder Basics.Int context (a -> a)
Ignore the ID of an entity while decoding.
keep : Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context ((a -> b) -> b)
Keep a particular attribute value to pass to the callback function for the entity being decoded.
ignore : Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context (b -> b)
Ignore a particular attribute so that it does not get passed to the callback function for the entity being decoded.
bool : Decoder Step.Types.Attribute context Basics.Bool
Decode a single attribute as a Bool
(from the special STEP enum values
.T.
and .F.
).
int : Decoder Step.Types.Attribute context Basics.Int
Decode a single attribute as an Int
.
float : Decoder Step.Types.Attribute context Basics.Float
Decode a single attribute as a Float
. Note that unlike JSON, STEP has
different encodings for Int
and Float
values so you cannot use this
function to decode integer values; if you want to decode an integer value as a
Float
you will need to use
Decode.map toFloat Decode.int
string : Decoder Step.Types.Attribute context String
Decode a single attribute as a String
.
emptyString : Decoder Step.Types.Attribute context ()
Decode a single attribute as a string which must be empty (whitespace only).
Useful when used with ignore
to check that the string being ignored
is in fact empty.
binaryData : Bytes.Decode.Decoder a -> Decoder Step.Types.Attribute context a
Decode a single attribute as a blob of binary data, using the given binary decoder.
derivedValue : a -> Decoder Step.Types.Attribute context a
Decode the special 'derived value' attribute (*
) as the given value.
null : a -> Decoder Step.Types.Attribute context a
Decode the special 'null' attribute ($
) as the given value.
optional : Decoder Step.Types.Attribute context output -> Decoder Step.Types.Attribute context (Maybe output)
Decode an attribute that may be null, returning Nothing
if it is.
enum : List ( String, a ) -> Decoder Step.Types.Attribute context a
Decode a single enum attribute, by passing a list of enum cases as their
STEP type name and corresponding Elm value. For example, given a STEP enum with
values RED
, YELLOW
and GREEN
you might write:
type LightColor
= Red
| Yellow
| Green
lightColorDecoder : Decoder Attribute LightColor
lightColorDecoder =
Decode.enum
[ ( "RED", Red )
, ( "YELLOW", Yellow )
, ( "GREEN", Green )
]
(Note that the given strings will be normalized, so case does not matter.)
list : Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context (List a)
Decode an attribute as a list, passing the decoder to be used for each list item.
tuple2 : Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context ( a, a )
Decode a list of exactly two elements, passing the decoder to be used for the two elements.
tuple3 : Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context ( a, a, a )
Decode a list of exactly three elements, passing the decoder to be used for the two elements.
referenceTo : Decoder Step.Types.Entity context a -> Decoder Step.Types.Attribute context a
Decode an attribute which is a reference to another entity, by providing the decoder to use for that entity.
referencedId : Decoder Step.Types.Attribute context Basics.Int
Decode just the ID from an entity reference attribute. This may be useful for deferred decoding/processing.
referenceWithId : (Basics.Int -> a -> b) -> Decoder Step.Types.Entity context a -> Decoder Step.Types.Attribute context b
Decode an attribute which is a reference to another entity, and additionally
get the ID of that entity. You will need to pass a function that combines the
ID and decoded value into whatever you want; for example if you pass
Tuple.pair
then you will get an ( Int, a )
value back.
typedAttribute : String -> Decoder Step.Types.Attribute context a -> Decoder Step.Types.Attribute context a
Decode a 'typed attribute'; for example if someone's age was stored as an
integer, then it might be encoded directly as an integer like 38
or as a typed
integer like AGE(38)
or YEARS(38)
or similar.
map : (a -> b) -> Decoder input context a -> Decoder input context b
Map the value produced by a decoder.
validate : (a -> Result String b) -> Decoder input context a -> Decoder input context b
Post-process the result of a decoder, either succeeding with a new value
(possibly of a different type) or failing with an error message. This is a
restricted form of andThen
that does not have the same performance concerns,
so use validate
instead of andThen
wherever possible.
resolve : Decoder input context (Result String output) -> Decoder input context output
If a decoder produces a Result String a
instead of simply a value of type
a
(for example if the callback function can fail) then this can 'resolve' that
back into a regular decoder. It is equivalent to (and implemented as)
validate identity
.
andThen : (a -> Decoder Step.Types.Entity context b) -> Decoder Step.Types.Entity context a -> Decoder Step.Types.Entity context b
Based on the result of one entity decoder, produce a second decoder to run on the same entity.
WARNING: This is sometimes necessary but can be a major performance issue!
Wherever possible, ensure decoders are created once instead of on the fly
inside an andThen
callback. For example, in some cases you may be able to
create a few static decoders and then have logic inside and andThen
simply
choose which of those to use.
succeed : a -> Decoder Step.Types.Entity context a
A trivial decoder that always succeeds with the given value. May be useful
in combination with andThen
, but consider using validate
instead.
fail : String -> Decoder Step.Types.Entity context a
A trivial decoder that always failes with the given error message. May be
useful in combination with andThen
, but consider using validate
instead.
lazy : (() -> Decoder Step.Types.Entity context a) -> Decoder Step.Types.Entity context a
Define a decoder lazily such that it is only constructed if needed. This is primarily used to break circular reference chains between decoders.
For efficiency reasons, you should make sure that the provided callback function simply returns an already-existing decoder value; it should not construct one on the fly.
chain : (context1 -> output1 -> context2) -> Decoder Step.Types.Entity context1 output1 -> Decoder Step.Types.Entity context2 output2 -> Decoder Step.Types.Entity context1 output2
Chain two decoders together so that the output of the first can affect the behavior of the second. Given two decoders, you must additionally pass a function that takes the context of the first decoder and its output, and produces the context to feed into the second decoder. The result is a combined decoder that accepts the context of the first and produces the output of the second.
filter : (context1 -> output1 -> Maybe context2) -> Decoder Step.Types.Entity context1 output1 -> Decoder Step.Types.Entity context2 output2 -> Decoder Step.Types.Entity context1 (Maybe output2)
A variant of chain
that additionally allows you to stop decoding
after the first step (never run the second decoder) by returning Nothing
instead of Just context
from the callback function. In that case the output
of the combined decoder will also be Nothing
.
inject : (outerContext -> innerContext) -> Decoder input innerContext output -> Decoder input outerContext output
Take a decoder that expects a particular type of context, and 'inject' part of the current context into it.
transform : (context -> a -> b) -> Decoder input context a -> Decoder input context b
Transform the result of a decoder using its context. This works just like
map
but additionally passes the current context to the mapping function.