Liking cljdoc? Tell your friends :D

cats.monad.state


evalclj/s

(eval state seed)

Given a State instance, execute the wrapped computation and return the resultant value, ignoring the state. Equivalent to taking the first value of the pair instance returned by run function.

Given a State instance, execute the
wrapped computation and return the resultant
value, ignoring the state.
Equivalent to taking the first value of the pair instance
returned by `run` function.
sourceraw docstring

execclj/s

(exec state seed)

Given a State instance, execute the wrapped computation and return the resultant state. Equivalent to taking the second value of the pair instance returned by run function.

Given a State instance, execute the
wrapped computation and return the resultant
state.
Equivalent to taking the second value of the pair instance
returned by `run` function.
sourceraw docstring

getclj/s

(get)
(get context)

Return a State instance with computation that returns the current state.

Return a State instance with computation that returns
the current state.
sourceraw docstring

getsclj/s

(gets projfn)
(gets projfn context)

State monad that returns the result of applying a function to a state

State monad that returns the result of applying
a function to a state
sourceraw docstring

MonadStateclj/sprotocol

A specific case of Monad abstraction for work with state in pure functional way.

A specific case of Monad abstraction for
work with state in pure functional way.

-get-stateclj/s

(-get-state m)

Return the current state.

Return the current state.

-put-stateclj/s

(-put-state m newstate)

Update the state.

Update the state.

-swap-stateclj/s

(-swap-state m f)

Apply a function to the current state and update it.

Apply a function to the current state and update it.
sourceraw docstring

putclj/s

(put newstate)
(put newstate context)

Return a State instance with computation that replaces the current state with specified new state.

Return a State instance with computation that replaces
the current state with specified new state.
sourceraw docstring

runclj/s

(run state seed)

Given a State instance, execute the wrapped computation and returns a cats.data.Pair instance with result and new state. (def computation (mlet [x (get-state) y (put-state (inc x))] (return y))) (def initial-state 1) (run computation initial-state) This should return something to: #<Pair [1 2]>

Given a State instance, execute the
wrapped computation and returns a cats.data.Pair
instance with result and new state.
  (def computation (mlet [x (get-state)
                          y (put-state (inc x))]
                     (return y)))
  (def initial-state 1)
  (run computation initial-state)
This should return something to: #<Pair [1 2]>
sourceraw docstring

stateclj/s

(state f)
(state f state-context)

The State type constructor. The purpose of State type is wrap a simple function that fullfill the state signature. It exists just for avoid extend the clojure function type because is very generic type.

The State type constructor.
The purpose of State type is wrap a simple
function that fullfill the state signature.
It exists just for avoid extend the clojure
function type because is very generic type.
sourceraw docstring

Stateclj/s

source

state?clj/s

(state? s)

Return true if s is instance of the State type.

Return true if `s` is instance of
the State type.
sourceraw docstring

swapclj/s

(swap f)
(swap f context)

Return a State instance with computation that applies the specified function to state and returns the old state.

Return a State instance with computation that applies the
specified function to state and returns the old state.
sourceraw docstring

wrap-fnclj/s

(wrap-fn my-fn)

Wraps a (possibly side-effecting) function to a state monad

Wraps a (possibly side-effecting) function to a state monad
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close