IzumiSy / elm-typed / Typed

Types


type Typed tag a p

A definition of Typed data.

Users can control data modifiability by giving permission to the type variable p.

Permissions


type alias ReadOnly =
{ read : Allowed
, write : Unallowed 
}

ReadOnly permission prohibits users to call all functions that do constructing and updating such as new, map and andThen.


type alias ReadWrite =
{ read : Allowed
, write : Allowed 
}

ReadWrite permission allows users to call all functions.


type alias WriteOnly =
{ read : Unallowed
, write : Allowed 
}

WriteOnly permission prohibits users to call value function to get internal implementation.

Policies


type alias Readable p =
{ p | read : Allowed }

Policy for allowing read permission.


type alias Writable p =
{ p | write : Allowed }

Policy for allowing write permission.

Constructor

new : a -> Typed tag a ReadWrite

writeOnly : a -> Typed tag a WriteOnly

Manipulation

value : Typed tag a (Readable p) -> a

map : (a -> a) -> Typed tag a (Writable p) -> Typed tag a (Writable p)

andThen : (a -> Typed tag b (Writable p)) -> Typed tag a (Writable p) -> Typed tag b (Writable p)

Serialization

encode : (a -> Json.Encode.Value) -> Typed tag a p -> Json.Encode.Value

decode : Json.Decode.Decoder a -> Json.Decode.Decoder (Typed tag a p)

encodeStrict : tag -> (a -> Json.Encode.Value) -> Typed tag a p -> Json.Encode.Value

Stricter version of encode that accepts a tag to check.

decodeStrict : tag -> Json.Decode.Decoder a -> Json.Decode.Decoder (Typed tag a p)

Stricter version of decode that accepts a tag to check.