Basic Monads.
Basic Monads.
Returns a Reader whose value is the environment.
Returns a Reader whose value is the environment.
(asks f)Returns a Reader whose value the result of applying f to the current environment.
Returns a Reader whose value the result of applying f to the current environment.
(either [v m] right-form)(either [v m] left-form right-form)Evaluates m. If the result is Left, binds its Left contents to v and evaluates left-form; otherwise binds its Right contents to v and evaluates right-form.
Evaluates m. If the result is Left, binds its Left contents to v and evaluates left-form; otherwise binds its Right contents to v and evaluates right-form.
(eval-state m s)Performs an action m with an initial state s. Returns the value.
Performs an action m with an initial state s. Returns the value.
(eval-writer m)Returns the value of a writer.
Returns the value of a writer.
(exec-state m s)Performs an action m with an initial state s. Returns the state.
Performs an action m with an initial state s. Returns the state.
(exec-writer m)Returns the output of a writer.
Returns the output of a writer.
Produces an action to return current state as the value.
Produces an action to return current state as the value.
(gets f)Like get-state, but applies the function f (usually a selector) on the state being return as the value of the inner monad.
Like get-state, but applies the function f (usually a selector) on the state being return as the value of the inner monad.
(just x)Maybe constructor. If x is not nil, it creates a Just value. If x is nil it creates a Nothing.
Maybe constructor. If x is not nil, it creates a Just value. If x is nil it creates a Nothing.
(just? m)Checks for a maybe with a value.
Checks for a maybe with a value.
(justs coll)Filters Just values from a collection. Returns unboxed values.
Filters Just values from a collection. Returns unboxed values.
(left? x)Tests if the receiver is a Left value.
Tests if the receiver is a Left value.
(lefts coll)Extracts the Left values from a collection. Returns unboxed values.
Extracts the Left values from a collection. Returns unboxed values.
(listen m)Allows chained Writers to peek at the current output w by returning a value as a pair (v, w).
Allows chained Writers to peek at the current output w by returning a value as a pair (v, w).
(local f m)Returns a Reader whose value is the result of running the Reader m under a changed environment, which is produced by applying f on the previous environment.
Returns a Reader whose value is the result of running the Reader m under a changed environment, which is produced by applying f on the previous environment.
(make-either form)(make-either message form)(make-either message pred form)Either constructor for a boxed value. It takes a value or a form that may evaluate to nil or throw an exception, both of which cases result in a Left value. Otherwise it is a Right value.
Either constructor for a boxed value. It takes a value or a form that may evaluate to nil or throw an exception, both of which cases result in a Left value. Otherwise it is a Right value.
(map-either f coll)Maps an Either-producing function over a collection. Returns a sequence with Left values removed, as unboxed values.
Maps an Either-producing function over a collection. Returns a sequence with Left values removed, as unboxed values.
(map-maybe f coll)Maps a Maybe-producing function over a collection. Filters out Nothing values and returns unboxed values.
Maps a Maybe-producing function over a collection. Filters out Nothing values and returns unboxed values.
(may [x m] then-form)(may [x m] then-form else-form)Like if-let for Maybe values. If m has a value, binds it to x and evaluates the then-form. Otherwise, evaluates the optional else-form.
Like if-let for Maybe values. If m has a value, binds it to x and evaluates the then-form. Otherwise, evaluates the optional else-form.
(maybe form)(maybe pred form)Maybe constructor for a boxed value. It takes a value or a form that may evaluate to nil or throw an exception, both of which cases result in a Nothing value.
Maybe constructor for a boxed value. It takes a value or a form that may evaluate to nil or throw an exception, both of which cases result in a Nothing value.
(modify-state f & more)Produces an action to apply f to the current state, using any given (optional) arguments. The result becomes the new state.
Produces an action to apply f to the current state, using any given (optional) arguments. The result becomes the new state.
(nothing? m)Checks for a maybe with nothing.
Checks for a maybe with nothing.
(pass m)Performs an action that returns a Writer similar to (listen), but instead of output it adds an output-transforming function to the value's pair. Returns a Writer whose output is the result of that function.
Performs an action that returns a Writer similar to (listen), but instead of output it adds an output-transforming function to the value's pair. Returns a Writer whose output is the result of that function.
(put-state s)Produces an action to set the current state.
Produces an action to set the current state.
(right? x)Tests if the receiver is a Right value.
Tests if the receiver is a Right value.
(rights coll)Extracts the Right values from a collection. Returns unboxed values.
Extracts the Right values from a collection. Returns unboxed values.
(run-id m)Returns the value held by an Identity type.
Returns the value held by an Identity type.
(run-just m)Returns the boxed value of m.
Returns the boxed value of m.
(run-left m)Accessor for the Left value.
Accessor for the Left value.
(run-reader m e)Performs a Reader action m with an environment e. Returns the value produced by the action.
Performs a Reader action m with an environment e. Returns the value produced by the action.
(run-right m)Accessor for the Right value.
Accessor for the Right value.
(run-state m s)Performs an action m with an initial state s. Returns a pair with the value and the state.
Performs an action m with an initial state s. Returns a pair with the value and the state.
(writer a)(writer a w)Writer monad constructor for value a and output w. The value w must implement Monoid. If w is not supplied, it defaults to the empty vector.
Writer monad constructor for value a and output w. The value w must implement Monoid. If w is not supplied, it defaults to the empty vector.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |