Cats Api Documentation

Version: 2.2.0

cats.monad.maybe

The Maybe monad implementation and helpers functions for working with maybe related types.

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

(maybe/just 1)
;; => #<Just [1]>

cat-maybes

(cat-maybes coll)

Given a collection of maybes, return a sequence of the values that the just’s contain.

from-maybe

(from-maybe mv)(from-maybe mv default)

Return inner value from maybe monad.

This is a specialized version of cats.core/extract for Maybe monad types that allows set up the default value.

Let see some examples:

(from-maybe (just 1))
;=> 1

(from-maybe (nothing))
;=> nil

(from-maybe (nothing) 42)
;=> 42

just

(just v)

A Just type constructor.

just?

(just? v)

Returns true if v is an instance of Just type.

map->Just

(map->Just m__7585__auto__)

Factory function for class cats.monad.maybe.Just, taking a map of keywords to field values.

map->Nothing

(map->Nothing m__7585__auto__)

Factory function for class cats.monad.maybe.Nothing, taking a map of keywords to field values.

map-maybe

(map-maybe mf coll)

Given a maybe-returning function and a collection, map the function over the collection returning the values contained in the just values of the resulting collection.

maybe

macro

(maybe default m f)

Given a default value, a maybe and a function, return the default if the maybe is a nothing; if its a just, apply the function to the value it contains and return the result.

maybe->seq

(maybe->seq m)

Given a maybe, return an empty seq if its nothing or a one-element seq with its value if its not.

maybe?

(maybe? v)

Return true in case of v is instance of Maybe monad.

nothing

(nothing)

A Nothing type constructor.

nothing?

(nothing? v)

Returns true if v is an instance of Nothing type or is nil.

seq->maybe

(seq->maybe coll)

Given a collection, return a nothing if its empty or a just with its first element if its not.