[{"name":"Val","comment":"\n\n@docs Val\n\n\n## who can create\n\n\n### tagged\n\n@docs Tagged, tag, map, map2\n\n\n### checked\n\n@docs Checked, isChecked\n\n\n## who can access\n\n\n### Public\n\n@docs Public, val, val2\n\n\n### internal\n\n@docs Internal, internal\n\n\n## serialize\n\n@docs serialize, serializeChecked\n\n","unions":[{"name":"Checked","comment":" Only someone with access to the `tag` constructor is able to create one of those.\n\nIn effect, this means that you can only let \"validated\" data be of this type.\n\nExamaple `... Checked ... NaturalNumberTag Int`\n\n→ **✓** not every `Int` can be called a `NaturalNumber`, it must be checked!\n\n","args":[],"cases":[]},{"name":"Internal","comment":" Only the ones with access to the `tag` constructor can access the `Val.internal`.\n\nMeaning that access can be limited to\n\n  - inside a module\n\n```\nmodule Special exposing (Special)\n\ntype alias Special =\n    Val Tagged SpecialTag Internal SpecialValue\n```\n\n  - inside a package (only with `Checked`)\n\n```\nsrc\n  └ Special\n      └ Internal.elm\n          module Special.Internal exposing (SpecialTag(..))\n  └ SpecialPartA.elm\n      module SpecialPartA exposing (SpecialPartA)\n      import Special.Internal exposing (SpecialTag(..))\n  └ SpecialPartB.elm\n      module SpecialPartB exposing (SpecialPartB)\n      import Special.Internal exposing (SpecialTag(..))\nelm.json 'exposed-modules' :\n  [ \"SpecialPartA\", \"SpecialPartB\" ]\n```\n\nThis generally helps hiding implementation details.\n\n    type alias OptimizedList a =\n        Val Checked OptimizedListTag Internal (Implementation a)\n\n    type alias Implementation a =\n        { list : List a, length : Int }\n\n    toList --...\n\n","args":[],"cases":[]},{"name":"Public","comment":" Anyone is able to access the value.\n","args":[],"cases":[]},{"name":"Tagged","comment":" Anyone is able to create one of those.\n\nExample `Val Tagged MetersTag ... Float`\n\n→ The right choice, as every `Float` is a valid description of `Meters`\n\n","args":[],"cases":[]},{"name":"Val","comment":" A value is wrapped in the `type Val` with a phantom `tag`.\n\nA `Val ... Meters ... Float` can't be called a `Val ... Kilos ... Float` anymore!\n\nFor `type`s with just 1 constructor with a value a `Val` can be a good replacement.\n\n\n### who can construct such a value\n\n  - [`Checked`](Val#Checked)\n\n  - [`Tagged`](Val#Tagged)\n\n\n### who can access the value\n\n  - [`Public`](Val#Public)\n\n  - [`Internal`](Val#Internal)\n\nall promise additional type-safety.\n\n\n### reading types\n\n    map :\n        (value -> mappedValue)\n        -> Val whoCanCreate tag whoCanAccess value\n        -> Val Tagged tag whoCanAccess\n\nIs saying: `map` works on every `Val` and returns a value that is just `Tagged`, but not `Checked`.\nExplaining `whoCanAccess`:\n\n  - If the input is `Public`\n  - If the input is `Internal`,\n\nthe result will be too.\n\n","args":["whoCreated","tag","whoCanAccess","value"],"cases":[]}],"aliases":[],"values":[{"name":"internal","comment":" If you have an `Internal`, its value isn't readable by users.\n\nIf you have the `tag` however, you can access this data hidden from users.\n\n","type":"tag -> Val.Val whoCanCreate tag Val.Internal value -> value"},{"name":"isChecked","comment":" After calling `tag` or modifying a checked value, you get a `Tagged`. To tell the type that the result value is `Checked`, use `isChecked tag`.\n\nThe type of `tag` might even change in that operation.\n\n    oddPlusOdd : Odd -> Odd -> Even\n    oddPlusOdd oddToAdd =\n        Val.map2 (+) oddToAdd\n            >> isChecked Even\n\n","type":"checkedTag -> Val.Val whoCreated tag whoCanAccess value -> Val.Val Val.Checked checkedTag whoCanAccessChecked value"},{"name":"map","comment":" Alter the value inside.\n\nIf the `Val` was a `Checked`, it becomes a `Tagged`.\n\n    type alias Meters =\n        Val Tagged MetersTag Public Int\n\n    go1km : Meters -> Meters\n    go1km =\n        Val.map ((+) 1000)\n\n","type":"(value -> mappedValue) -> Val.Val whoCreated tag whoCanAccess value -> Val.Val Val.Tagged tag whoCanAccess mappedValue"},{"name":"map2","comment":" Use the values of 2 `Val`s to return a result. The result becomes a `Tagged`.\n\n    type alias PrimeNumber =\n        Val Checked PrimeNumberTag Public Int\n\n    prime3 : PrimeNumber\n    prime3 =\n        tag 3 |> isChecked PrimeNumber\n\n    prime5 =\n        tag 5 |> isChecked PrimeNumber\n\nIn another module\n\n    type alias NonPrime =\n        Val Checked NonPrimeTag Public Int\n\n    fromMultiplyingPrimes : Prime -> Prime -> NonPrime\n    fromMultiplyingPrimes aPrime bPrime =\n        Val.map2 (*) aPrime bPrime\n            |> isChecked NonPrime\n\n","type":"(aValue -> bValue -> combinedValue) -> Val.Val whoCanCreateA aTag whoCanAccess aValue -> Val.Val whoCanCreateB bTag whoCanAccess bValue -> Val.Val Val.Tagged combinedTag whoCanAccess combinedValue"},{"name":"serialize","comment":" A [`Codec`](https://package.elm-lang.org/packages/MartinSStewart/elm-serialize/latest/) to serialize `Tagged` `Public` `Val`s.\n","type":"Serialize.Codec error value -> Serialize.Codec error (Val.Val Val.Tagged tag Val.Public value)"},{"name":"serializeChecked","comment":" A [`Codec`](https://package.elm-lang.org/packages/MartinSStewart/elm-serialize/latest/) to serialize `Checked`s.\n\nWe don't trust that the values we encode still have the same promises as our `Checked`s.\n\nChoose a value it can convert from & to and serialize that.\n\n    module Nat exposing (serialize)\n\n    type NatTag\n        = Nat\n\n    serialize =\n        Serialize.int\n            |> Val.serializeChecked Nat\n                (\\int ->\n                    if int >= 0 then\n                        Ok int\n\n                    else\n                        Err \"Int was negative, so it couldn't be decoded as a Nat\"\n                )\n\n    module EfficientList exposing (serialize)\n\n    type EfficientListTag\n        = EfficientList\n\n    type alias EfficientList =\n        Val Checked EfficientListTag\n            Internal { list : List a, length : Int }\n\n    serialize =\n        Serialize.map .list identity\n            |> Serialize.list\n            |> Val.serializeChecked EfficientList\n                (\\list ->\n                    { list = list\n                    , length = List.length length\n                    }\n                        |> Ok\n                )\n\n","type":"tag -> (value -> Result.Result error value) -> Serialize.Codec error value -> Serialize.Codec error (Val.Val Val.Checked tag whoCanAccess value)"},{"name":"tag","comment":" Create a new tagged value.\n\n  - can be `Checked` with [`isChecked`](Val#isChecked)\n  - becomes `Internal/Public` when annotated that way\n\nModifying won't change the type.\n\n","type":"value -> Val.Val Val.Tagged tag whoCanAccess value"},{"name":"val","comment":" Read the value inside a `Public` `Val`.\n","type":"Val.Val whoCreated tag Val.Public value -> value"},{"name":"val2","comment":" Use the values of 2 `Accessible`s to return a result.\n\n    type alias Prime =\n        Val Checked PrimeTag Public Int\n\n    prime3 =\n        tag 3 |> isChecked Prime\n\n    prime5 =\n        tag 5 |> isChecked Prime\n\nAnywhere\n\n    val2 (+) prime3 prime5\n    --> 8\n\n    val2 Tuple.pair prime3 prime5\n    --> ( 3, 5 )\n\n    if val2 (<) onePrime otherPrime then\n\n","type":"(aValue -> bValue -> resultValue) -> Val.Val whoCreatedA aTag Val.Public aValue -> Val.Val whoCreatedB bTag Val.Public bValue -> resultValue"}],"binops":[]}]