[{"name":"Json.Decode.Attempt","comment":" When decoding Json, there is usually a hard trade off\n\n1.  Risk failing to decode (bad) in order to get error messages (good)\n2.  Have fallbacks (good) but suppress error messages (bad)\n\nThis attempt decoding technique is a way to get the good of both.\nThe result of decoding an `Attempt` gives you the value you sought\nand a list of errors it accumulated along the way.\n\n\n# Attempt\n\n@docs Attempt, Dangerously, Safely\n\n\n# Pipeline\n\n@docs try, risk, applySafely, applyDangerously\n\n\n# Basics\n\n@docs fromDecoder, fromValue, fromDecoderWithFallback, fallbackTo, field, map\n\n\n# Decode\n\n@docs decodeStringDangerously, decodeStringSafely, decodeValueDangerously, decodeValueSafely\n\n","unions":[{"name":"Attempt","comment":" An attempt at decoding a particular `value`. The `safety` parameter describes\nif this kind of attempt will be able to recover or if it will fail hard.\n","args":["value","safety"],"cases":[]},{"name":"Dangerously","comment":" A marker that this `Attempt value Dangerously` cannot be safely decoded straight to\na `value`, and it may fail in a big way that doesnt deliver a `value` at all. In addition,\nif it does succeed decoding a `value`, it still preserves the `Decode.Error` is found\nalong the way.\n\n    type alias User =\n        { id : Int\n        , name : Maybe String\n        }\n\n    decodeUser : Decode.Value -> Result Decode.Error ( User, List Decode.Error )\n    decodeUser json =\n        let\n            attemptUser : Attempt User Dangerously\n            attemptUser =\n                Attempt.succeed User\n                    |> Attempt.risk (Decode.field \"id\" Decode.int)\n                    |> Attempt.try (Decode.map Just <| Decode.field \"name\" Decode.string) Nothing\n        in\n        Attempt.decodeValueDangerously attemptUser json\n\n","args":[],"cases":[]},{"name":"Safely","comment":" A marker that this `Attempt value Safely` can be safely decoded straight to\na `value`, without an intermediate `Result Decode.Error value`. In this example\nbelow, `attemptInt` will always give you an `OperatingSystem`, and it may or\nmay not give you an error too.\n\n    attemptOperatingSystem : Attempt OperatingSystem Safely\n    attemptOperatingSystem =\n        Attempt.fromDecoderWithDefault\n            (Decode.field \"operating_system\" OperatingSystem.decoder)\n            OperatingSystem.NotDetected\n\n    ( value, errors ) =\n        Attempt.decodeValueSafely attemptOperatingSystem\n\n","args":[],"cases":[]}],"aliases":[],"values":[{"name":"applyDangerously","comment":" Apply a dangerous attempt to a pipeline, turning the rest of the pipeline into a dangerous attempt.\nKind of like a more general form of `risk`.\n\n    risk : Decoder a -> Attempt (a -> b) safety -> Attempt b Dangerously\n    risk decoder =\n        applyDangerously (fromDecoder decoder)\n\n    type Id\n        = Id Int\n\n    attemptId : Attempt Id Dangerous\n    attemptId =\n        Attempt.succeed Id\n            |> Attempt.risk Decode.int\n\n","type":"Json.Decode.Attempt.Attempt a Json.Decode.Attempt.Dangerously -> Json.Decode.Attempt.Attempt (a -> b) safety -> Json.Decode.Attempt.Attempt b Json.Decode.Attempt.Dangerously"},{"name":"applySafely","comment":" Apply a safe attempt to a pipeline. Kind of like a more general form of `try`\n\n    try : Decoder a -> a -> Attempt (a -> b) safety -> Attempt b safety\n    try decoder fallback =\n        applySafely (fromDecoderWithFallback decoder fallback)\n\n    type alias Flags =\n        { landingPageUrl : String }\n\n    attemptFlags : Attempt Flags Safely\n    attemptFlags =\n        Attempt.succeed Flags\n            |> Attempt.applySafely (fromDecoderWithFallback Decode.string (Route.toString Route.home))\n\n","type":"Json.Decode.Attempt.Attempt a Json.Decode.Attempt.Safely -> Json.Decode.Attempt.Attempt (a -> b) safety -> Json.Decode.Attempt.Attempt b safety"},{"name":"decodeStringDangerously","comment":" Just like `decodeValueDangerously`, except it takes a `String` instead of a `Decode.Value`. Just like\nthe difference between `Decode.decodeValue` and `Decode.decodeString`.\n","type":"Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Dangerously -> String.String -> Result.Result Json.Decode.Error ( value, List.List Json.Decode.Error )"},{"name":"decodeStringSafely","comment":" Just like `decodeValueSafely`, except it takes a `String` instead of a `Decode.Value`. Just like\nthe difference between `Decode.decodeValue` and `Decode.decodeString`.\n","type":"Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Safely -> String.String -> ( value, List.List Json.Decode.Error )"},{"name":"decodeValueDangerously","comment":" The final step in an attempt to decode json. This function takes a dangerous attempt,\nand therefore it can possibly fail. If it does succeed, the `Ok` case is `(value, List Decode.Error)`,\ncontaining both the desired `value` and the `List Decode.Error` of non-critical errors it encountered\nalong the way.\n","type":"Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Dangerously -> Json.Decode.Value -> Result.Result Json.Decode.Error ( value, List.List Json.Decode.Error )"},{"name":"decodeValueSafely","comment":" The final step in an attempt to decode json. This function takes a safe attempt, and\ntherefore can never fail. It will pass along both the value you intended to decode, and\na list of whatever errors it encountered along the way.\n","type":"Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Safely -> Json.Decode.Value -> ( value, List.List Json.Decode.Error )"},{"name":"fallbackTo","comment":" Take a dangerous attempt, and specify how it should fall back, thereby making it a safe attempt\n","type":"value -> Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Dangerously -> Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Safely"},{"name":"field","comment":" Attempt to decode json that is under a certain field, much like `Decode.field`. By checking\nunder a field, you risk the field not being present in the first place, so using `field` is always `Dangerous`\n\n    type alias User =\n        { id : Int\n        , name : Maybe String\n        , car : Car\n        }\n\n    type alias Car =\n        { plateNumber : Maybe String\n        , miles : Maybe Int\n        }\n\n    attemptCar : Attempt Car Safely\n    attemptCar =\n        Attempt.fromValue Car\n            |> Attempt.try (Decode.map Just <| Decode.field \"plate_number\" Decode.string) Nothing\n            |> Attempt.try (Decode.map Just <| Decode.field \"miles\" Decode.int) Nothing\n\n    attemptUser : Attempt User Dangerously\n    attemptUser =\n        Attempt.fromValue User\n            |> Attempt.risk (Decode.field \"id\" Decode.int)\n            |> Attempt.try (Decode.map Just <| Decode.field \"name\" Decode.string) Nothing\n            |> Attempt.applyDangerously (Attempt.field \"car\" attemptCar)\n\n","type":"String.String -> Json.Decode.Attempt.Attempt value safety -> Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Dangerously"},{"name":"fromDecoder","comment":" Use a decoder in an attempt. Since the decoder might fail, the resulting\nattempt is a `Dangerous` one.\n","type":"Json.Decode.Decoder a -> Json.Decode.Attempt.Attempt a Json.Decode.Attempt.Dangerously"},{"name":"fromDecoderWithFallback","comment":" Use a decoder in an attempt, with a fallback. Since a fallback is provided,\nthe attempt is safe\n","type":"Json.Decode.Decoder a -> a -> Json.Decode.Attempt.Attempt a Json.Decode.Attempt.Safely"},{"name":"fromValue","comment":" Convert a value into an attempt, presumably to use it in a pipeline. Since the\nvalue is provided outright the Attempt is safe\n","type":"value -> Json.Decode.Attempt.Attempt value Json.Decode.Attempt.Safely"},{"name":"map","comment":" Convert the value of an `Attempt` from one type to another\n","type":"(a -> b) -> Json.Decode.Attempt.Attempt a safety -> Json.Decode.Attempt.Attempt b safety"},{"name":"risk","comment":" Try a decoder, and risk it failing, thereby transforming your attempt into a `Dangerous` one\n\n    type Id\n        = Id Int\n\n    attemptId : Attempt Id Dangerous\n    attemptId =\n        Attempt.succeed Id\n            |> Attempt.risk Decode.int\n\n","type":"Json.Decode.Decoder a -> Json.Decode.Attempt.Attempt (a -> b) safety -> Json.Decode.Attempt.Attempt b Json.Decode.Attempt.Dangerously"},{"name":"try","comment":" Try a decoder, and if it fails, fallback `Safely` to a fallback value\n\n    type alias Flags =\n        { landingPageUrl : String }\n\n    attemptFlags : Attempt Flags Safely\n    attemptFlags =\n        Attempt.succeed Flags\n            |> Attempt.try Decode.string (Route.toString Route.home)\n\n","type":"Json.Decode.Decoder a -> a -> Json.Decode.Attempt.Attempt (a -> b) safety -> Json.Decode.Attempt.Attempt b safety"}],"binops":[]}]