No matching definitions.

tur/lens

stdlib/lens.tur

first-class functional lenses (getter/setter optics).

Since: constrained-hkt-forall slice 4

defstruct

Lens

(defstruct Lens :copy [S A])
defn

lens

(lens [S A])

build a Lens from a getter and a setter.

getreads the focused A out of the whole S
putreturns a new S with the focused A replaced

A Lens S A pairing `get` and `put`.

(lens (fn [p : Point] : int (.x p))
        (fn [nx : int p : Point] : Point
          (make-struct Point :x nx :y (.y p))))

Since: constrained-hkt-forall slice 4

defn

view

(view [S A])

read the focused A out of the whole S.

lthe lens
sthe whole value

The focused part A.

(view point-x p)   ; => (.x p)

Since: constrained-hkt-forall slice 4

defn

set

(set [S A])

replace the focused A, returning the updated S.

lthe lens
athe new focused value
sthe whole value

A new S with the focus replaced by `a`.

(set point-x 42 p)   ; => p with x = 42

Since: constrained-hkt-forall slice 4

defn

over

(over [S A])

apply a function to the focused A, returning the updated S.

lthe lens
ftransforms the focused value
sthe whole value

A new S with the focus mapped through `f`.

(over point-x (fn [v : int] : int (* v 10)) p)   ; => p with x *= 10

Since: constrained-hkt-forall slice 4