terezka / yaml / Yaml.Decode

Turn YAML values into Elm values. The library is structured the same way as a Json.Decode in elm/json, so if you haven't worked with decoders before, reading through the guide maybe be helpful.


type Decoder a

A value that knows how to decode YAML values.

There is a whole section in guide.elm-lang.org about decoders, so check it out for a more comprehensive introduction!


type Error
    = Parsing String
    | Decoding String

fromString : Decoder a -> String -> Result Error a

Primitives

string : Decoder String

Decode a YAML string into an Elm String.

bool : Decoder Basics.Bool

Decode a YAML boolean into an Elm Bool.

int : Decoder Basics.Int

Decode a YAML number into an Elm Int.

float : Decoder Basics.Float

Decode a YAML number into an Elm Float.

Data Structures

nullable : Decoder a -> Decoder (Maybe a)

Decode a nullable YAML value into an Elm value.

list : Decoder a -> Decoder (List a)

Decode a YAML array into an Elm List.

Object Primitives

field : String -> Decoder a -> Decoder a

Decode a YAML object, requiring a particular field.

The object can have other fields. Lots of them! The only thing this decoder cares about is if x is present and that the value there is an Int.

Check out map2 to see how to decode multiple fields!

at : List String -> Decoder a -> Decoder a

Decode a nested YAML object, requiring certain fields.

Maps

map : (a -> b) -> Decoder a -> Decoder b

Transform a decoder.

map2 : (a -> b -> c) -> Decoder a -> Decoder b -> Decoder c

Try two decoders and then combine the result.

map3 : (a -> b -> c -> d) -> Decoder a -> Decoder b -> Decoder c -> Decoder d

Try three decoders and then combine the result.

map4 : (a -> b -> c -> d -> e) -> Decoder a -> Decoder b -> Decoder c -> Decoder d -> Decoder e

Try four decoders and then combine the result.

map5 : (a -> b -> c -> d -> e -> f) -> Decoder a -> Decoder b -> Decoder c -> Decoder d -> Decoder e -> Decoder f

Try five decoders and then combine the result.

map6 : (a -> b -> c -> d -> e -> f -> g) -> Decoder a -> Decoder b -> Decoder c -> Decoder d -> Decoder e -> Decoder f -> Decoder g

Try six decoders and then combine the result.

map7 : (a -> b -> c -> d -> e -> f -> g -> h) -> Decoder a -> Decoder b -> Decoder c -> Decoder d -> Decoder e -> Decoder f -> Decoder g -> Decoder h

Try seven decoders and then combine the result.

map8 : (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Decoder a -> Decoder b -> Decoder c -> Decoder d -> Decoder e -> Decoder f -> Decoder g -> Decoder h -> Decoder i

Try seven decoders and then combine the result.

Special


type alias Value =
Yaml.Parser.Value

Represents a YAML value.

value : Decoder Value

Do not do anything with a YAML value, just bring it into Elm as a Value. This can be useful if you have particularly complex data that you would like to deal with later.

sometimes : Decoder a -> Decoder (Maybe a)

A decoder which returns Nothing when it fails.

Note: This is equivalent to maybe from Json.Decode.

fail : String -> Decoder a

Ignore the YAML and make the decoder fail. This is handy when used with oneOf or andThen where you want to give a custom error message in some case.

See the andThen docs for an example.

succeed : a -> Decoder a

Ignore the YAML and produce a certain Elm value.

andThen : (a -> Decoder b) -> Decoder a -> Decoder b

Create decoders that depend on previous results.