@@ -6,7 +6,7 @@ module Json.Decode
6 , list, dict, maybe
6 , list, dict, maybe
7 , field, at
7 , field, at
9− , map, map2, succeed, fail, andThen
9+ , map, map2, succeed, fail, andThen, oneOf
@@ -37,6 +37,7 @@ data Decoder a =
38 = Field Text Error
38 = Field Text Error
39 | Index Int Error
39 | Index Int Error
40 | Failure Aeson.Value String
41 | Failure Aeson.Value String
@@ -269,3 +270,27 @@ andThen callback (Decoder runA) =
269 do a <- runA mkError value
270 do a <- runA mkError value
270 let (Decoder runB) = callback a
271 let (Decoder runB) = callback a
271 runB mkError value
272 runB mkError value
279+oneOf :: [Decoder a] -> Decoder a
281+ Decoder (oneOfHelp decoders [])
284+oneOfHelp :: [Decoder a] -> [Error] -> (Error -> Error) -> Aeson.Value -> Either Error a
285+oneOfHelp decoders errors mkError value =
288+ Left (mkError (OneOf (reverse errors)))
290+ Decoder run : otherDecoders ->
291+ case run mkError value of
296+ oneOfHelp otherDecoders (err:errors) mkError value