Lentes Api Documentation

Version: 1.2.0

lentes.core

->ROFocus

(->ROFocus id lens src check-equals? watchers srccache oldcache cache)

->RWFocus

(->RWFocus id lens src check-equals? watchers srccache oldcache cache)

const-setter

(const-setter s _)

The constant setter, returns the state unaltered.

derive

(derive lens src)(derive lens src {:keys [read-only? check-equals?], :or {read-only? false, check-equals? true}})

Create a derived atom from an other atom with the provided lense.

The returned atom is lazy, so no code is executed until user requires it.

By default the deriveed atom does not trigger updates if the data does not affects to it (determined by lense), but this behavior can be deactivated passing :check-equals? to false on the third options parameter.

You can create expliclitly read only refs (not atoms, because the returned object satisifies watchable and ref but not atom interface) passing :read-only? as true as option on the optional third parameter.

focus

(focus lens s)

Given a lens and a state, return the value focused by the lens.

id

Identity lens.

id-setter

(id-setter s f)

The identity setter, applies the function to the state.

in

(in path)(in path default)

Given a path and optionally a default value, return a lens that focuses the given path in an associative data structure.

key

(key k)

Given a key, returns a lens that focuses on the given key of an associative data structure.

lens

(lens getter)(lens getter setter)

Given a function for getting the focused value from a state (getter) and a function that takes the state and and update function (setter), constructs a lens.

nth

(nth n)

Given a number, returns a lens that focuses on the given index of a collection.

over

(over st f s)

Given a setter, a function and a state, apply the function over the value focused by the setter.

passes

(passes applies?)

Given a predicate, return a lens that focuses in an element only if passes the predicate.

The lens is not well-behaved, depens on the outcome of the predicate.

put

(put st v s)

Given a setter, a new value and a state, replace the value focused by the lens with the new one.

select-keys

(select-keys ks)

Return a lens focused on the given keys in an associative data structure.

tail

A lens into the tail of a collection.

units

(units one->other other->one)

Given a function from unit A to unit B and another in the opposite direction, construct a lens that focuses and updates a converted value.