An implementation of Func that's specialized to Applicative.
Represents a function F[A] => B
.
Const is a phantom type, it does not contain a value of its second type parameter B
Const can be seen as a type level version of Function.const[A, B]: A => B => A
F
on the left and G
on the right of Xor.
Func is a function A => F[B]
.
Func is a function A => F[B]
.
Represents a right-biased disjunction that is either an A
, or a B
, or both an A
and a B
.
Represents a right-biased disjunction that is either an A
, or a B
, or both an A
and a B
.
An instance of A Ior B
is one of:
A Ior B
is similar to A Xor B
, except that it can represent the simultaneous presence of
an A
and a B
. It is right-biased like Xor, so methods such as map
and flatMap
operate on the
B
value. Some methods, like flatMap
, handle the presence of two Both values using a
Semigroup[A]
, while other methods, like toXor, ignore the A
value in a Both.
A Ior B
is isomorphic to (A Xor B) Xor (A, B)
, but provides methods biased toward B
values, regardless of whether the B
values appear in a Right or a Both.
The isomorphic Xor form can be accessed via the unwrap method.
Represents a function A => F[B]
.
A data type which represents a single element (head) and some other structure (tail).
A data type which represents a single element (head) and some other structure (tail). As we have done in package.scala, this can be used to represent a List which is guaranteed to not be empty:
type NonEmptyList[A] = OneAnd[List, A]
OptionT[F[_], A]
is a light wrapper on an F[Option[A]]
with some
convenient methods for working with this nested structure.
OptionT[F[_], A]
is a light wrapper on an F[Option[A]]
with some
convenient methods for working with this nested structure.
It may also be said that OptionT
is a monad transformer for Option
.
For more information, see the documentation.
Prod is a product to two independent functor values.
Prod is a product to two independent functor values.
StateT[F, S, A]
is similar to Kleisli[F, S, A]
in that it takes an S
argument and produces an A
value wrapped in F
.
StateT[F, S, A]
is similar to Kleisli[F, S, A]
in that it takes an S
argument and produces an A
value wrapped in F
. However, it also produces
an S
value representing the updated state (which is wrapped in the F
context along with the A
value.
Represents a right-biased disjunction that is either an A
or a B
.
Represents a right-biased disjunction that is either an A
or a B
.
An instance of A Xor B
is either a Left[A]
or a Right[B]
.
A common use of Xor is to explicitly represent the possibility of failure in a result as opposed to
throwing an exception. By convention, Left is used for errors and Right is reserved for successes.
For example, a function that attempts to parse an integer from a string may have a return type of
NumberFormatException Xor Int
. However, since there is no need to actually throw an exception, the type (A
)
chosen for the "left" could be any type representing an error and has no need to actually extend Exception
.
A Xor B
is isomorphic to scala.Either[A, B]
, but Xor is right-biased, so methods such as map
and
flatMap
apply only in the context of the "right" case. This right bias makes Xor more convenient to use
than scala.Either
in a monadic context. Methods such as swap
, and leftMap
provide functionality
that scala.Either
exposes through left projections.
Transformer for Xor
, allowing the effect of an arbitrary type constructor F
to be combined with the
fail-fast effect of Xor
.
Transformer for Xor
, allowing the effect of an arbitrary type constructor F
to be combined with the
fail-fast effect of Xor
.
XorT[F, A, B]
wraps a value of type F[A Xor B]
. An F[C]
can be lifted in to XorT[F, A, C]
via XorT.right
,
and lifted in to a XorT[F, C, B]
via XorT.left
.