Much like the Id
type in the non-remote version of this module, except now the Id
might also point to the error
that occured when trying to load the item
.
fromString : String -> Id error x
Make an id from a string
Id.fromString "vq93rUv0A4"
toString : Id error x -> String
Extract the string from an id.
encode : Id error x -> Json.Encode.Value
Encode an Id
Encode.encode 0 (Id.encode id)
-- ""hDFL0Cs2EqWJ4jc3kMtOrKdEUTWh"" : String
[ ("id", Id.encode id) ]
|> Encode.object
|> Encode.encode 0
-- {\"id\":\"hDFL0Cs2EqWJ4jc3kMtOrKdEUTWh\"} : String
decoder : Json.Decode.Decoder (Id error x)
Decode an Id
Decode.decodeString (Decode.field "id" Id.decoder) "{\"id\":\"19\"}"
-- Ok (Id "19") : Result String Id
generator : Random.Generator (Id error x)
A way to generate random Id
s
import Id exposing (Id)
import Random exposing (Seed)
user : Seed -> ( User, Seed )
user seed =
let
( id, nextSeed ) =
Random.step Id.generator seed
in
( { id = id, email = "Bob@sci.org" }
, nextSeed
)