[{"name":"Validation","comment":" A `Validation` represents either success or failure.\n\n@docs Validation\n\n\n# Construct\n\n@docs succeed\n@docs fail, failWithErrors\n@docs fromResult, fromMaybe\n\n\n# Query\n\n@docs isValid, isInvalid\n\n\n# Map\n\n@docs map, map2, map3, map4, map5\n@docs mapError\n\n\n# Apply\n\n@docs apply\n\n\n# Chain\n\n@docs andThen\n\n\n# Convert\n\n@docs withDefault, toResult, toMaybe\n\n\n# Handle Errors\n\n@docs firstError, lastError, allErrors\n\n","unions":[{"name":"Validation","comment":" It can fail with one or more errors. The major difference between `Validation` and `Result` is that\nwhen validations are composed their errors accumulate.\n","args":["error","value"],"cases":[]}],"aliases":[],"values":[{"name":"allErrors","comment":"\n\n    allErrors (succeed 5) == []\n\n    allErrors (fail \"x\") == [ \"x\" ]\n\n    allErrors (failWithErrors \"x\" [ \"y\", \"z\" ]) == [ \"x\", \"y\", \"z\" ]\n\n","type":"Validation.Validation e a -> List.List e"},{"name":"andThen","comment":" Chain together a sequence of validations that may fail.\n\nWe only continue with the callback if things are going well.\n\n\n    toInt : String -> Validation String Int\n    toInt rawString =\n        fromMaybe \"cannot convert to an Int\" (String.toInt rawString)\n\n    toMonthFromInt : Int -> Validation String Int\n    toMonthFromInt anyInt =\n        if anyInt >= 1 && anyInt <= 12 then\n            succeed anyInt\n\n        else\n            fail \"months must be between 1 and 12\"\n\n    toMonthFromString : String -> Validation String Int\n    toMonthFromString rawString =\n        toInt rawString\n            |> andThen toMonthFromInt\n\n    -- toMonthFromString \"4\" == succeed 4\n    -- toMonthFromString \"9\" == succeed 9\n    -- toMonthFromString \"a\" == fail \"cannot convert to an Int\"\n    -- toMonthFromString \"0\" == fail \"months must be between 1 and 12\"\n\n","type":"(a -> Validation.Validation x b) -> Validation.Validation x a -> Validation.Validation x b"},{"name":"apply","comment":" Adds support for an applicative style of programming.\n\nPractically, it means that when you need to go beyond `map5` you can use this function together with [`succeed`](#succeed) to achieve it. For e.g.\n\n    succeed (\\a b c d e f g h i j k -> ...)\n        |> apply va\n        |> apply vb\n        |> apply vc\n        |> apply vd\n        |> apply ve\n        |> apply vf\n        |> apply vg\n        |> apply vh\n        |> apply vi\n        |> apply vj\n        |> apply vk\n\n","type":"Validation.Validation x a -> Validation.Validation x (a -> b) -> Validation.Validation x b"},{"name":"fail","comment":" ","type":"e -> Validation.Validation e a"},{"name":"failWithErrors","comment":" ","type":"e -> List.List e -> Validation.Validation e a"},{"name":"firstError","comment":"\n\n    firstError (succeed 5) == Nothing\n\n    firstError (fail \"x\") == Just \"x\"\n\n    firstError (failWithErrors \"x\" [ \"y\", \"z\" ]) == Just \"x\"\n\n","type":"Validation.Validation e a -> Maybe.Maybe e"},{"name":"fromMaybe","comment":"\n\n    fromMaybe \"x\" (Just 5) == succeed 5\n\n    fromMaybe \"x\" Nothing == fail \"x\"\n\n","type":"e -> Maybe.Maybe a -> Validation.Validation e a"},{"name":"fromResult","comment":"\n\n    fromResult (Ok 5) == succeed 5\n\n    fromResult (Err \"x\") == fail \"x\"\n\n","type":"Result.Result e a -> Validation.Validation e a"},{"name":"isInvalid","comment":"\n\n    isInvalid (succeed 5) == False\n\n    isInvalid (fail \"x\") == True\n\n","type":"Validation.Validation e a -> Basics.Bool"},{"name":"isValid","comment":"\n\n    isValid (succeed 5) == True\n\n    isValid (fail \"x\") == False\n\n","type":"Validation.Validation e a -> Basics.Bool"},{"name":"lastError","comment":"\n\n    lastError (succeed 5) == Nothing\n\n    lastError (fail \"x\") == Just \"x\"\n\n    lastError (failWithErrors \"x\" [ \"y\", \"z\" ]) == Just \"z\"\n\n","type":"Validation.Validation e a -> Maybe.Maybe e"},{"name":"map","comment":" Apply a function to a validation. If the validation is a success, the value will be converted. If the validation is\na failure, the same error will be propagated.\n\n    map sqrt (succeed 4.0) == succeed 2.0\n\n    map sqrt (fail \"bad input\") == fail \"bad input\"\n\n","type":"(a -> value) -> Validation.Validation x a -> Validation.Validation x value"},{"name":"map2","comment":" Apply a function if both validations are a success. If not, the errors will be accumulated in order of failure.\n\n    map2 max (succeed 42) (succeed 13) == succeed 42\n\n    map2 max (fail \"x\") (succeed 13) == fail \"x\"\n\n    map2 max (succeed 42) (fail \"y\") == fail \"y\"\n\n    map2 max (fail \"x\") (fail \"y\") == failWithErrors \"x\" [ \"y\" ]\n\n","type":"(a -> b -> value) -> Validation.Validation x a -> Validation.Validation x b -> Validation.Validation x value"},{"name":"map3","comment":" Apply a function if all three validations are a success. If not, the errors will be accumulated in order of failure.\n\n    map3 (\\a b c -> a + b + c) (succeed 1) (succeed 2) (succeed 3) == succeed 6\n\n    map3 (\\a b c -> a + b + c) (succeed 1) (fail \"y\") (succeed 3) == fail \"y\"\n\n    map3 (\\a b c -> a + b + c) (fail \"x\") (succeed 2) (fail \"z\") == failWithErrors \"x\" [ \"z\" ]\n\n    map3 (\\a b c -> a + b + c) (fail \"x\") (fail \"y\") (fail \"z\") == failWithErrors \"x\" [ \"y\", \"z\" ]\n\n","type":"(a -> b -> c -> value) -> Validation.Validation x a -> Validation.Validation x b -> Validation.Validation x c -> Validation.Validation x value"},{"name":"map4","comment":" ","type":"(a -> b -> c -> d -> value) -> Validation.Validation x a -> Validation.Validation x b -> Validation.Validation x c -> Validation.Validation x d -> Validation.Validation x value"},{"name":"map5","comment":" ","type":"(a -> b -> c -> d -> e -> value) -> Validation.Validation x a -> Validation.Validation x b -> Validation.Validation x c -> Validation.Validation x d -> Validation.Validation x e -> Validation.Validation x value"},{"name":"mapError","comment":" ","type":"(x -> y) -> Validation.Validation x a -> Validation.Validation y a"},{"name":"succeed","comment":" ","type":"a -> Validation.Validation e a"},{"name":"toMaybe","comment":"\n\n    toMaybe (succeed 5) == Just 5\n\n    toMaybe (fail \"x\") == Nothing\n\n    toMaybe (failWithErrors \"x\" [ \"y\" ]) == Nothing\n\n","type":"Validation.Validation e a -> Maybe.Maybe a"},{"name":"toResult","comment":"\n\n    toResult (succeed 5) == Ok 5\n\n    toResult (fail \"x\") == Err [ \"x\" ]\n\n    toResult (failWithErrors \"x\" [ \"y\" ]) == Err [ \"x\", \"y\" ]\n\n","type":"Validation.Validation e a -> Result.Result (List.List e) a"},{"name":"withDefault","comment":"\n\n    withDefault 0 (succeed 5) == 5\n\n    withDefault 0 (fail \"x\") == 0\n\n","type":"a -> Validation.Validation e a -> a"}],"binops":[]}]