Liking cljdoc? Tell your friends :D

cats.core

Category Theory abstractions for Clojure

Category Theory abstractions for Clojure
raw docstring

<$>clj/s

(<$> f)
(<$> f fv)

Alias of fmap.

Alias of fmap.
sourceraw docstring

<*>clj/s

(<*> af av)
(<*> af av & avs)

Performs a Haskell-style left-associative fapply.

Performs a Haskell-style left-associative fapply.
sourceraw docstring

<=<clj/s

(<=< mg mf x)

Right-to-left composition of monads. Same as >=> with its first two arguments flipped.

Right-to-left composition of monads.
Same as `>=>` with its first two arguments flipped.
sourceraw docstring

=<<clj/s

(=<< f mv)

Same as the two argument version of >>= but with the arguments interchanged.

Same as the two argument version of `>>=` but with the
arguments interchanged.
sourceraw docstring

>=>clj/s

(>=> mf mg x)

Left-to-right composition of monads.

Left-to-right composition of monads.
sourceraw docstring

>>clj/s

(>> mv mv')
(>> mv mv' & mvs)

Performs a Haskell-style left-associative bind, ignoring the values produced by the monad computations.

Performs a Haskell-style left-associative bind,
ignoring the values produced by the monad computations.
sourceraw docstring

>>=clj/s

(>>= mv f)
(>>= mv f & fs)

Performs a Haskell-style left-associative bind.

Let see it in action:

(>>= (just 1) (comp just inc) (comp just inc))
;; => #<Just [3]>
Performs a Haskell-style left-associative
bind.

Let see it in action:

    (>>= (just 1) (comp just inc) (comp just inc))
    ;; => #<Just [3]>
sourceraw docstring

bindclj/s

(bind mv f)

Given a value inside monadic context mv and any function, applies a function to value of mv.

(bind (either/right 1) (fn [v]
                         (return (inc v))))
;; => #<Right [2]>

For convenience, you may prefer use a mlet macro that add a beautiful, let like syntax for compose operations with bind function.

Given a value inside monadic context `mv` and any function,
applies a function to value of mv.

    (bind (either/right 1) (fn [v]
                             (return (inc v))))
    ;; => #<Right [2]>

For convenience, you may prefer use a `mlet` macro
that add a beautiful, let like syntax for
compose operations with `bind` function.
sourceraw docstring

extractclj/s

(extract v)

Generic function for unwrap/extract the inner value of a container.

Generic function for unwrap/extract
the inner value of a container.
sourceraw docstring

fapplyclj/s

(fapply af av)

Given function inside af's conext and value inside av's context, applies the function to value and return a result wrapped in context of same type of av context.

Given function inside af's conext and value inside
av's context, applies the function to value and return
a result wrapped in context of same type of av context.
sourceraw docstring

filterclj/s

(filter p mv)

Applies a predicate to a value in a MonadZero instance, returning the identity element when the predicate yields false.

Otherwise, returns the instance unchanged.

(require '[cats.monad.moaybe :as maybe])
(require '[cats.core :as m])

(m/filter (partial < 2) (maybe/just 3))
;=> <Just [3]>

(m/filter (partial < 4) (maybe/just 3))
;=> <Nothing>
Applies a predicate to a value in a `MonadZero` instance,
returning the identity element when the predicate yields false.

Otherwise, returns the instance unchanged.

    (require '[cats.monad.moaybe :as maybe])
    (require '[cats.core :as m])

    (m/filter (partial < 2) (maybe/just 3))
    ;=> <Just [3]>

    (m/filter (partial < 4) (maybe/just 3))
    ;=> <Nothing>
sourceraw docstring

fmapclj/s

(fmap f fv)

Apply a function f to the value inside functor's fv preserving the context type.

Apply a function f to the value inside functor's fv
preserving the context type.
sourceraw docstring

forseqclj/s

(forseq vs mf)

Same as mapseq but with the arguments in reverse order.

Let se a little example:

(m/forseq [2 3] maybe/just)
;; => <Just [[2 3]]>

Yet an other example that fails:

(m/forseq [1 2]
          (fn [v]
            (if (odd? v)
              (maybe/just v)
              (maybe/nothing))))
;; => <Nothing>
Same as mapseq but with the arguments in reverse order.

Let se a little example:

    (m/forseq [2 3] maybe/just)
    ;; => <Just [[2 3]]>

Yet an other example that fails:

    (m/forseq [1 2]
              (fn [v]
                (if (odd? v)
                  (maybe/just v)
                  (maybe/nothing))))
    ;; => <Nothing>
sourceraw docstring

guardclj/s

(guard b)
source

joinclj/s

(join mv)

Remove one level of monadic structure. This is same as that (bind mv identity)

Remove one level of monadic structure.
This is same as that `(bind mv identity)`
sourceraw docstring

liftclj/s

(lift mv)
(lift m mv)

Lift a value from the inner monad of a monad transformer into a value of the monad transformer.

Lift a value from the inner monad of a monad transformer
into a value of the monad transformer.
sourceraw docstring

lift-mclj/smacro

(lift-m n f)

Lifts a function with the given fixed number of arguments to a monadic context.

(def monad+ (lift-m 2 +))

(monad+ (maybe/just 1) (maybe/just 2))
;; => <Just [3]>

(monad+ (maybe/just 1) (maybe/nothing))
;; => <Nothing>

(monad+ [0 2 4] [1 2])
;; => [1 2 3 4 5 6]
Lifts a function with the given fixed number of arguments to a
monadic context.

    (def monad+ (lift-m 2 +))

    (monad+ (maybe/just 1) (maybe/just 2))
    ;; => <Just [3]>

    (monad+ (maybe/just 1) (maybe/nothing))
    ;; => <Nothing>

    (monad+ [0 2 4] [1 2])
    ;; => [1 2 3 4 5 6]
sourceraw docstring

mapseqclj/s

(mapseq mf coll)

Given a function that takes a value and puts it into a monadic context, map it into the given collection calling sequence on the results.

(require '[cats.monad.maybe :as maybe])
(require '[cats.core :as m])

(m/mapseq maybe/just [2 3])
;=> <Just [[2 3]]>

(m/mapseq (fn [v]
             (if (odd? v)
               (maybe/just v)
               (maybe/nothing)))
            [1 2])
;=> <Nothing>
Given a function that takes a value and puts it into a
monadic context, map it into the given collection
calling sequence on the results.

    (require '[cats.monad.maybe :as maybe])
    (require '[cats.core :as m])

    (m/mapseq maybe/just [2 3])
    ;=> <Just [[2 3]]>

    (m/mapseq (fn [v]
                 (if (odd? v)
                   (maybe/just v)
                   (maybe/nothing)))
                [1 2])
    ;=> <Nothing>
sourceraw docstring

mletclj/smacro

(mlet bindings & body)

Monad composition macro that works like clojure let. This allows much easy composition of monadic computations.

Let see one example for understand how it works, this is a code using bind for compose few number of operations:

(bind (just 1)
      (fn [a]
        (bind (just (inc a))
              (fn [b]
                (return (* b 2))))))
;=> #<Just [4]>

Now see how this code can be more clear if you are using mlet macro for do it:

(mlet [a (just 1)
       b (just (inc a))]
  (return (* b 2)))
;=> #<Just [4]>
Monad composition macro that works like clojure
let. This allows much easy composition of monadic
computations.

Let see one example for understand how it works, this is
a code using bind for compose few number of operations:

    (bind (just 1)
          (fn [a]
            (bind (just (inc a))
                  (fn [b]
                    (return (* b 2))))))
    ;=> #<Just [4]>

Now see how this code can be more clear if you
are using mlet macro for do it:

    (mlet [a (just 1)
           b (just (inc a))]
      (return (* b 2)))
    ;=> #<Just [4]>
sourceraw docstring

mplusclj/s

(mplus & mvs)
source

mzeroclj/s

(mzero)
source

pureclj/s

(pure v)
(pure ctx v)

Given any value v, return it wrapped in default/effect free context.

This is multiarity function that with arity pure/1 it uses the dynamic scope to resolve the current context. With pure/2, you can force a specific context value.

Example:

(with-monad either/either-monad
  (pure 1)
;; => #<Right [1]>
Given any value v, return it wrapped in
default/effect free context.

This is multiarity function that with arity pure/1
it uses the dynamic scope to resolve the current
context. With `pure/2`, you can force a specific context
value.

Example:

    (with-monad either/either-monad
      (pure 1)
    ;; => #<Right [1]>
sourceraw docstring

returnclj/s

(return v)
(return ctx v)

This is a monad version of pure and it works identically to it.

This is a monad version of pure and it works
identically to it.
sourceraw docstring

sequenceclj/s

(sequence mvs)

Given a non-empty collection of monadic values, collect their values in a vector returned in the monadic context.

(sequence [(maybe/just 2) (maybe/just 3)])
;; => <Just [[2, 3]]>

(sequence [(maybe/nothing) (maybe/just 3)])
;; => <Nothing>
Given a non-empty collection of monadic values, collect
their values in a vector returned in the monadic context.

    (sequence [(maybe/just 2) (maybe/just 3)])
    ;; => <Just [[2, 3]]>

    (sequence [(maybe/nothing) (maybe/just 3)])
    ;; => <Nothing>
sourceraw docstring

unlessclj/s

(unless b mv)

If the expression is false, returns the monadic value. Otherwise, yields nil in a monadic context.

If the expression is false, returns the monadic value.
Otherwise, yields nil in a monadic context.
sourceraw docstring

whenclj/s

(when b mv)
(when ctx b mv)

If the expression is true, returns the monadic value. Otherwise, yields nil in a monadic context.

If the expression is true, returns the monadic value.
Otherwise, yields nil in a monadic context.
sourceraw docstring

with-monadclj/smacro

(with-monad ctx & body)

Set current context to specific monad.

Set current context to specific monad.
sourceraw docstring

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

× close