Liking cljdoc? Tell your friends :D

monads.core


>>clj

(>> m c)
source

>>=clj

(>>= m f)
source

askclj

Return the current environment.

Return the current environment.
sourceraw docstring

asksclj

(asks f & args)

Return the environment transformed by the function f, with extra args args.

Return the environment transformed by the function f, with extra args args.
sourceraw docstring

catch-errorclj

(catch-error comp handler)

Try running the computation comp, calling the function handler if it is aborted by an error. The handler function will receive the error value as its argument.

Try running the computation comp, calling the function handler if
it is aborted by an error. The handler function will receive the
error value as its argument.
sourceraw docstring

censorclj

(censor f m)

Execute the computation m, returning the value it returns and modifying its log by the function f.

Execute the computation m, returning the value it returns and modifying
its log by the function f.
sourceraw docstring

defmonadcljmacro

(defmonad name & params)
source

failclj

(fail msg)

Abort the current computation, with the message msg (if supported).

Abort the current computation, with the message msg (if supported).
sourceraw docstring

get-stateclj

Return the current state

Return the current state
sourceraw docstring

joinclj

(join m)
source

liftclj

(lift inner)

Lift the computation inner up a level in the monad transformer stack.

Lift the computation inner up a level in the monad transformer stack.
sourceraw docstring

lift-mclj

(lift-m f)
(lift-m f m)

Transform a function a -> b into a monadic function m a -> m b.

Transform a function a -> b into a monadic function m a -> m b.
sourceraw docstring

listenclj

(listen comp)

Execute the computation comp, and return both its return value and the log it produces.

Execute the computation comp, and return both its return value and
the log it produces.
sourceraw docstring

listensclj

(listens f m)

Execute the computation m, adding the result of calling f on its log to the its return value.

Execute the computation m, adding the result of calling f on its log to
the its return value.
sourceraw docstring

localclj

(local f comp)

Run the computation comp in an environment transformed by the function f.

Run the computation comp in an environment transformed by the function f.
sourceraw docstring

mdocljmacro

(mdo & exprs)

Special syntax for monadic computations. An mdo form contains one of three kinds of elements:

  • binding elements, which have the form destructure <- expression;

  • plain elements, which are just expressions (except that they cannot consist solely of the symbol <- or the symbol let;

  • let elements, which can be either

    let destructure1 = expression1 destructure2 = expression2 ...

    or

    let [destructure1 expression1 destructure2 expression2 ...]

mdo forms must end with a plain element.

These are rewritten into clojure.core/let expressions, and binding using >>= and anonymous functions. For instance (from treenumber.clj in examples):

(mdo num <- (number-node val) nt1 <- (number-tree left) nt2 <- (number-tree right) let [new-node (node num nt1 nt2)] (return new-node))

becomes

(>>= (number-node val) (fn [num] (>>= (number-tree left) (fn [nt1] (>>= (number-tree right) (fn [nt2] (let [new-node (node num nt1 nt2)] (return new-node))))))))

Note that plain elements can include arbitrary Clojure control or binding expressions (so let expressions don't actually need to be baked in); the above could also have been:

(mdo num <- (number-node val) nt1 <- (number-tree left) nt2 <- (number-tree right) (let [new-node (node num nt1 nt2)] (return new-node)))

Special syntax for monadic computations. An `mdo` form contains one of three kinds of elements:

- binding elements, which have the form `destructure <- expression`;

- plain elements, which are just expressions (except that they
  cannot consist solely of the symbol `<-` or the symbol `let`;

- let elements, which can be either

     let destructure1 = expression1
         destructure2 = expression2
         ...

  or

     let [destructure1 expression1
          destructure2 expression2
          ...]

`mdo` forms must end with a plain element.

These are rewritten into clojure.core/let expressions, and binding
using >>= and anonymous functions. For instance (from
treenumber.clj in examples):

(mdo num <- (number-node val)
     nt1 <- (number-tree left)
     nt2 <- (number-tree right)
     let [new-node (node num nt1 nt2)]
     (return new-node))

becomes

(>>= (number-node val)
     (fn [num] (>>= (number-tree left)
                    (fn [nt1] (>>= (number-tree right)
                                  (fn [nt2] (let [new-node (node num nt1 nt2)]
                                                  (return new-node))))))))

Note that plain elements can include arbitrary Clojure control or
binding expressions (so let expressions don't actually need to be
baked in); the above could also have been:

(mdo num <- (number-node val)
     nt1 <- (number-tree left)
     nt2 <- (number-tree right)
     (let [new-node (node num nt1 nt2)]
          (return new-node)))
sourceraw docstring

modifyclj

(modify f & args)

Transform the current state by the function f, with extra args args.

Transform the current state by the function f, with extra args args.
sourceraw docstring

monadcljmacro

(monad & params)
source

mplusclj

(mplus left right)

Add the values of left and right. Required to be associative.

Add the values of left and right. Required to be associative.
sourceraw docstring

mzeroclj

The zero value for monadplus instances

The zero value for monadplus instances
sourceraw docstring

passclj

(pass comp)

Execute the computation comp, which should return a value and a function, and return the value, applying the function to the log.

Execute the computation comp, which should return a value and a
function, and return the value, applying the function to the log.
sourceraw docstring

put-stateclj

(put-state v)

Make the state be the value v.

Make the state be the value v.
sourceraw docstring

reify+cljmacro

(reify+ & signatures)

Like reify, except that one can conditionally decide what interfaces to implement, using "when".

The syntax of reify is extended to allow both

Protocol (method [] ...)

lines and also

(when condition Protocol2 (method2 [] ...))

If, at runtime, condition is truthy, the reified value will also support Protocol2.

Like reify, except that one can conditionally decide what
interfaces to implement, using "when".

The syntax of reify is extended to allow both

Protocol
(method [] ...)

lines and also

(when condition
   Protocol2
   (method2 [] ...))

If, at runtime, condition is truthy, the reified value will also
support Protocol2.
sourceraw docstring

returnclj

(return x)
source

run-mdocljmacro

(run-mdo m & exprs)
source

run-monadclj

(run-monad m computation)
source

tellclj

(tell w)

Add the value w to the log. Note that w must be a monoid.

Add the value w to the log. Note that w must be a monoid.
sourceraw docstring

throw-errorclj

(throw-error e)

Abort the current computation, with the error e.

Abort the current computation, with the error e.
sourceraw docstring

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

× close