bChiquet / elm-accessors / Accessors.Lazy

Lazy versions of set, over.

These actions check that the old and the new version are different before writing. They are useful when used together with Html.lazy, because it uses reference equality for complex structures. Therefore, using lazy set and over will not prevent Html.lazy from doing its work.

get is also reexported for convenience.

get : (Accessors.Internal.Relation sub sub sub -> Accessors.Internal.Relation super sub wrap) -> super -> wrap

The get function takes: An accessor, A datastructure with type super and returns the value accessed by that combinator.

get (foo << bar) myRecord 

set : (Accessors.Internal.Relation sub sub sub -> Accessors.Internal.Relation super sub wrap) -> sub -> super -> super

The set function takes: An accessor, A value of the type sub, * A datastructure with type super and it returns the data structure, with the accessible field changed to the set value. The structure is changed only if the new field is different from the old one.

set (foo << bar) "Hi!" myRecord

over : (Accessors.Internal.Relation sub sub sub -> Accessors.Internal.Relation super sub wrap) -> (sub -> sub) -> super -> super

The over function takes: An accessor, A function (sub -> sub), * A datastructure with type super and it returns the data structure, with the accessible field changed by applying the function to the existing value. The structure is changed only if the new field is different from the old one.

over (foo << qux) ((+) 1) myRecord