Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upExample for Json.Decode.value wrong in documentation #364
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jvoigtlaender
Aug 22, 2015
Contributor
A possible fix is this:
variadic2 : (a -> b -> List c -> value) -> Decoder a -> Decoder b -> Decoder c -> Decoder value
variadic2 f a b c =
customDecoder (list value) (\jsonList ->
case jsonList of
one :: two :: rest ->
Result.map3 f
(decodeValue a one)
(decodeValue b two)
(combine (List.map (decodeValue c) rest))
_ -> Result.Err "expecting at least two elements in the array")where
combine : List (Result x a) -> Result x (List a)
combine = List.foldr (Result.map2 (::)) (Ok [])is a function analogous to http://package.elm-lang.org/packages/Apanatshka/elm-signal-extra/5.4.1/Signal-Extra#combine (or to http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Traversable.html#v:sequenceA).
|
A possible fix is this: variadic2 : (a -> b -> List c -> value) -> Decoder a -> Decoder b -> Decoder c -> Decoder value
variadic2 f a b c =
customDecoder (list value) (\jsonList ->
case jsonList of
one :: two :: rest ->
Result.map3 f
(decodeValue a one)
(decodeValue b two)
(combine (List.map (decodeValue c) rest))
_ -> Result.Err "expecting at least two elements in the array")where combine : List (Result x a) -> Result x (List a)
combine = List.foldr (Result.map2 (::)) (Ok [])is a function analogous to http://package.elm-lang.org/packages/Apanatshka/elm-signal-extra/5.4.1/Signal-Extra#combine (or to http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Traversable.html#v:sequenceA). |
This was referenced Aug 22, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
Closing via https://github.com/elm-lang/core/pull/365. |
jvoigtlaender
closed this
Aug 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jvoigtlaender commentedAug 22, 2015
The example at http://package.elm-lang.org/packages/elm-lang/core/2.1.0/Json-Decode#value is missing some brackets. Adding them gives:
But that's not type-correct according to http://elm-lang.org/try. (It complains about mismatched types
Valuevs.List Valuein the 2nd argument of(decodeValue cs rest).)