Cats Api Documentation

Version: 2.2.0

cats.monad.either

The Either monad implementation and helper functions for working with either related types.

Also commonly known as Error monad.

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

(either/right 1)
;; => #<Right [1]>

(either/left 1)
;; => #<Left [1]>

branch

(branch e lf rf)

Given an either value and two functions, if the either is a left apply the first function to the value it contains; if the either is a right apply the second function to its value.

branch-left

(branch-left e lf)

Given an either value and a function, if the either is a left, apply the function to the value it contains; if the either is a right, return it.

branch-right

(branch-right e rf)

Either-specific synonym for #’cats.core/bind

Given an either value and a function, if the either is a right, apply the function to the value it contains; if the either is a left, return it.

either?

(either? v)

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

first-left

Given a collection of either, return the first value that is left

first-right

Given a collection of either, return the first value that is right

invert

(invert e)

Convert a left to a right or viceversa, preserving content.

left

(left)(left v)

A Left type constructor.

left?

(left? v)

Return true if v is an instance of Left type.

lefts

Given a collection of eithers, return only the values that are left.

map->Left

(map->Left m__7585__auto__)

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

map->Right

(map->Right m__7585__auto__)

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

right

(right)(right v)

A Right type constructor.

right?

(right? v)

Return true if v is an instance of Right type.

rights

Given a collection of eithers, return only the values that are right.

try-either

macro

(try-either & body)

Try to evalute the body and return the result as an either. If an exception is thrown return the exception as a left, otherwise return the result as a right.