package data
- Alphabetic
- By Inheritance
- data
- ScalaVersionSpecificPackage
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
sealed abstract
class
AndThen[-T, +R] extends (T) ⇒ R with Product with Serializable
A function type of a single input that can do function composition (via
andThen
andcompose
) in constant stack space with amortized linear time application (in the number of constituent functions).A function type of a single input that can do function composition (via
andThen
andcompose
) in constant stack space with amortized linear time application (in the number of constituent functions).Example:
val seed = AndThen((x: Int) => x + 1) val f = (0 until 10000).foldLeft(seed)((acc, _) => acc.andThen(_ + 1)) // This should not trigger stack overflow ;-) f(0)
This can be used to build stack safe data structures that make use of lambdas. The perfect candidates for usage with
AndThen
are the data structures using a signature like this (whereF[_]
is a monadic type):A => F[B]
As an example, if we described this data structure, the naive solution for that
map
is stack unsafe:case class Resource[F[_], A, B]( acquire: F[A], use: A => F[B], release: A => F[Unit]) { def flatMap[C](f: B => C)(implicit F: Functor[F]): Resource[F, A, C] = { Resource( ra.acquire, // Stack Unsafe! a => ra.use(a).map(f), ra.release) } }
To describe a
flatMap
operation for this data type,AndThen
can save the day:def flatMap[C](f: B => C)(implicit F: Functor[F]): Resource[F, A, C] = { Resource( ra.acquire, AndThen(ra.use).andThen(_.map(f)), ra.release) }
-
sealed abstract
class
AppFunc[F[_], A, B] extends Func[F, A, B]
An implementation of Func that's specialized to Applicative.
-
final
case class
Binested[F[_, _], G[_], H[_], A, B](value: F[G[A], H[B]]) extends Product with Serializable
Compose a two-slot type constructor
F[_, _]
with two single-slot type constructorsG[_]
andH[_]
, resulting in a two-slot type constructor with respect to the inner types.Compose a two-slot type constructor
F[_, _]
with two single-slot type constructorsG[_]
andH[_]
, resulting in a two-slot type constructor with respect to the inner types. For example,List
andOption
both haveFunctor
instances, andEither
has aBifunctor
instance. Therefore,Binested[Either, List, Option, *, *]
has aBifunctor
instance as well:scala> import cats.Bifunctor scala> import cats.data.Binested scala> import cats.implicits._ scala> val eitherListOption: Either[List[Int], Option[String]] = Right(Some("cats")) scala> val f: Int => String = _.toString scala> val g: String => String = _ + "-bifunctor" scala> val binested = Binested(eitherListOption) scala> val bimapped = Bifunctor[Binested[Either, List, Option, *, *]].bimap(binested)(f, g).value res0: Either[List[String], Option[String]] = Right(Some("cats-bifunctor"))
- sealed abstract class BinestedBifoldable[F[_, _], G[_], H[_]] extends Bifoldable[[δ$12$, ε$13$]Binested[F, G, H, δ$12$, ε$13$]]
- sealed abstract class BinestedBitraverse[F[_, _], G[_], H[_]] extends BinestedBifoldable[F, G, H] with Bitraverse[[δ$14$, ε$15$]Binested[F, G, H, δ$14$, ε$15$]]
- trait BinestedInstances extends BinestedInstances0
-
sealed abstract
class
Chain[+A] extends AnyRef
Trivial catenable sequence.
Trivial catenable sequence. Supports O(1) append, and (amortized) O(1)
uncons
, such that walking the sequence via N successiveuncons
steps takes O(N). -
final
case class
Cokleisli[F[_], A, B](run: (F[A]) ⇒ B) extends Product with Serializable
Represents a function
F[A] => B
. -
final
case class
Const[A, B](getConst: A) extends Product with Serializable
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 ofFunction.const[A, B]: A => B => A
- type Cont[A, B] = ContT[Eval, A, B]
-
sealed abstract
class
ContT[M[_], A, +B] extends Serializable
This is a continuation transformer based on the ContT in the Haskell package Control.Monad.Cont
This is a continuation transformer based on the ContT in the Haskell package Control.Monad.Cont
This is reasonably straight-forward except that to make a tailRecM implementation we leverage the Defer type class to obtain stack-safety.
-
final
case class
EitherK[F[_], G[_], A](run: Either[F[A], G[A]]) extends Product with Serializable
F
on the left andG
on the right ofscala.util.Either
.F
on the left andG
on the right ofscala.util.Either
.- run
The underlying
scala.util.Either
.
- type EitherNec[+E, +A] = Either[NonEmptyChain[E], A]
- type EitherNel[+E, +A] = Either[NonEmptyList[E], A]
- type EitherNes[E, +A] = Either[NonEmptySet[E], A]
-
final
case class
EitherT[F[_], A, B](value: F[Either[A, B]]) extends Product with Serializable
Transformer for
Either
, allowing the effect of an arbitrary type constructorF
to be combined with the fail-fast effect ofEither
.Transformer for
Either
, allowing the effect of an arbitrary type constructorF
to be combined with the fail-fast effect ofEither
.EitherT[F, A, B]
wraps a value of typeF[Either[A, B]]
. AnF[C]
can be lifted in toEitherT[F, A, C]
viaEitherT.right
, and lifted in to aEitherT[F, C, B]
viaEitherT.left
. -
sealed abstract
class
Func[F[_], A, B] extends AnyRef
Func is a function
A => F[B]
.Func is a function
A => F[B]
. - type IRWST[F[_], E, L, SA, SB, A] = IndexedReaderWriterStateT[F, E, L, SA, SB, A]
-
final
case class
IdT[F[_], A](value: F[A]) extends Product with Serializable
IdT[F[_], A]
is the identity monad transformer. -
final
class
IndexedReaderWriterStateT[F[_], E, L, SA, SB, A] extends Serializable
Represents a stateful computation in a context
F[_]
, from stateSA
to stateSB
, with an initial environmentE
, an accumulated logL
and a resultA
.Represents a stateful computation in a context
F[_]
, from stateSA
to stateSB
, with an initial environmentE
, an accumulated logL
and a resultA
.In other words, it is a pre-baked stack of
ReaderT[F, E, A]
,WriterT[F, L, A]
andIndexedStateT[F, SA, SB, A]
. - type IndexedState[S1, S2, A] = IndexedStateT[Eval, S1, S2, A]
-
final
class
IndexedStateT[F[_], SA, SB, A] extends Serializable
IndexedStateT[F, SA, SB, A]
is a stateful computation in a contextF
yielding a value of typeA
.IndexedStateT[F, SA, SB, A]
is a stateful computation in a contextF
yielding a value of typeA
. The state transitions from a value of typeSA
to a value of typeSB
.Note that for the
SA != SB
case, this is an indexed monad. Indexed monads are monadic type constructors annotated by an additional type for effect tracking purposes. In this case, the annotation tracks the initial state and the resulting state.Given
IndexedStateT[F, S, S, A]
, this yields theStateT[F, S, A]
monad. -
sealed abstract
class
Ior[+A, +B] extends Product with Serializable
Represents a right-biased disjunction that is either an
A
, or aB
, or both anA
and aB
.Represents a right-biased disjunction that is either an
A
, or aB
, or both anA
and aB
.An instance of
A Ior B
is one of:A Ior B
is similar toscala.util.Either[A, B]
, except that it can represent the simultaneous presence of anA
and aB
. It is right-biased so methods such asmap
andflatMap
operate on theB
value. Some methods, likeflatMap
, handle the presence of two Both values using aSemigroup[A]
, while other methods, like toEither, ignore theA
value in a Both.A Ior B
is isomorphic toEither[Either[A, B], (A, B)]
, but provides methods biased towardB
values, regardless of whether theB
values appear in a Right or a Both. The isomorphicscala.util.Either
form can be accessed via the unwrap method. - type IorNec[+B, +A] = Ior[NonEmptyChain[B], A]
- type IorNel[+B, +A] = Ior[NonEmptyList[B], A]
- type IorNes[B, +A] = Ior[NonEmptySet[B], A]
- final case class IorT[F[_], A, B](value: F[Ior[A, B]]) extends Product with Serializable
-
final
case class
Kleisli[F[_], -A, B](run: (A) ⇒ F[B]) extends Product with Serializable
Represents a function
A => F[B]
. - final class KleisliFromFunctionPartiallyApplied[M[_], R] extends AnyRef
-
final
case class
Nested[F[_], G[_], A](value: F[G[A]]) extends Product with Serializable
Similar to cats.data.Tuple2K, but for nested composition.
Similar to cats.data.Tuple2K, but for nested composition.
For instance, since both
List
andOption
have aFunctor
, then so doesList[Option[_]]
. This is represented by this data type via the instantiationNested[List, Option, *]
.scala> import cats.Functor scala> import cats.data.Nested scala> import cats.implicits._ scala> val listOption: List[Option[Int]] = List(Some(1), None) scala> val f: Int => String = i => (i * 2).toString scala> Functor[List].map(listOption)(opt => opt.map(f)) res0: List[Option[String]] = List(Some(2), None) scala> val nested: Nested[List, Option, Int] = Nested(listOption) scala> val result: Nested[List, Option, String] = Functor[Nested[List, Option, *]].map(nested)(f) scala> result.value res1: List[Option[String]] = List(Some(2), None)
- type NonEmptyChain[+A] = Type[A]
- final class NonEmptyChainOps[A] extends AnyVal with NonEmptyCollection[A, Chain, NonEmptyChain]
-
final
case class
NonEmptyList[+A](head: A, tail: List[A]) extends NonEmptyCollection[A, List, NonEmptyList] with Product with Serializable
A data type which represents a non empty list of A, with single element (head) and optional structure (tail).
- type NonEmptyMap[K, +A] = data.NonEmptyMapImpl.Type[K, A]
- sealed class NonEmptyMapOps[K, A] extends AnyRef
-
final
class
NonEmptySeq[+A] extends AnyVal with NonEmptyCollection[A, Seq, NonEmptySeq]
A data type which represents a
Seq
guaranteed to contain at least one element.A data type which represents a
Seq
guaranteed to contain at least one element.
Note that the constructor isprivate
to prevent accidental construction of an emptyNonEmptySeq
. However, due to https://issues.scala-lang.org/browse/SI-6601, on Scala 2.10, this may be bypassed due to a compiler bug. - type NonEmptySet[A] = data.NonEmptySetImpl.Type[A]
-
sealed
class
NonEmptySetOps[A] extends AnyRef
- Annotations
- @suppressUnusedImportWarningForScalaVersionSpecific()
-
type
NonEmptyStream[A] = OneAnd[Stream, A]
- Definition Classes
- ScalaVersionSpecificPackage
-
final
class
NonEmptyVector[+A] extends AnyVal with NonEmptyCollection[A, Vector, NonEmptyVector]
A data type which represents a
Vector
guaranteed to contain at least one element.A data type which represents a
Vector
guaranteed to contain at least one element.
Note that the constructor isprivate
to prevent accidental construction of an emptyNonEmptyVector
. However, due to https://issues.scala-lang.org/browse/SI-6601, on Scala 2.10, this may be bypassed due to a compiler bug. -
final
case class
OneAnd[F[_], A](head: A, tail: F[A]) extends Product with Serializable
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 Stream which is guaranteed to not be empty:
type NonEmptyStream[A] = OneAnd[Stream, A]
-
final
case class
Op[Arr[_, _], A, B](run: Arr[B, A]) extends Product with Serializable
The dual category of some other category,
Arr
. -
final
case class
OptionT[F[_], A](value: F[Option[A]]) extends Product with Serializable
OptionT[F[_], A]
is a light wrapper on anF[Option[A]]
with some convenient methods for working with this nested structure.OptionT[F[_], A]
is a light wrapper on anF[Option[A]]
with some convenient methods for working with this nested structure.It may also be said that
OptionT
is a monad transformer forOption
.For more information, see the documentation.
- type RWS[E, L, S, A] = IndexedReaderWriterStateT[Eval, E, L, S, S, A]
- type RWST[F[_], E, L, S, A] = IndexedReaderWriterStateT[F, E, L, S, S, A]
- type Reader[-A, B] = Kleisli[Id, A, B]
- type ReaderT[F[_], -A, B] = Kleisli[F, A, B]
- type ReaderWriterState[E, L, S, A] = IndexedReaderWriterStateT[Eval, E, L, S, S, A]
-
type
ReaderWriterStateT[F[_], E, L, S, A] = IndexedReaderWriterStateT[F, E, L, S, S, A]
Represents a stateful computation in a context
F[_]
, over stateS
, with an initial environmentE
, an accumulated logL
and a resultA
. -
final
case class
RepresentableStore[F[_], S, A](fa: F[A], index: S)(implicit R: Aux[F, S]) extends Product with Serializable
A generalization of
StoreT
, where the underlying functorF
has aRepresentable
instance.A generalization of
StoreT
, where the underlying functorF
has aRepresentable
instance.Store
is the dual ofState
- final case class RepresentableStoreT[W[_], F[_], S, A](runF: W[F[A]], index: S)(implicit F: Aux[F, S]) extends Product with Serializable
- trait RepresentableStoreTInstances1 extends RepresentableStoreTInstances2
- trait RepresentableStoreTInstances2 extends AnyRef
- type State[S, A] = IndexedStateT[Eval, S, S, A]
-
type
StateT[F[_], S, A] = IndexedStateT[F, S, S, A]
StateT[F, S, A]
is similar toKleisli[F, S, A]
in that it takes anS
argument and produces anA
value wrapped inF
.StateT[F, S, A]
is similar toKleisli[F, S, A]
in that it takes anS
argument and produces anA
value wrapped inF
. However, it also produces anS
value representing the updated state (which is wrapped in theF
context along with theA
value. - type Store[S, A] = RepresentableStore[[β$0$](S) ⇒ β$0$, S, A]
- type StoreT[W[_], S, A] = RepresentableStoreT[W, [β$2$](S) ⇒ β$2$, S, A]
-
final
case class
Tuple2K[F[_], G[_], A](first: F[A], second: G[A]) extends Product with Serializable
Tuple2K is a product to two independent functor values.
Tuple2K is a product to two independent functor values.
- sealed abstract class Validated[+E, +A] extends Product with Serializable
- type ValidatedNec[+E, +A] = Validated[NonEmptyChain[E], A]
- type ValidatedNel[+E, +A] = Validated[NonEmptyList[E], A]
- type Writer[L, V] = WriterT[Id, L, V]
- final case class WriterT[F[_], L, V](run: F[(L, V)]) extends Product with Serializable
- final class ZipList[A] extends AnyVal
- final class ZipSeq[A] extends AnyVal
- final class ZipStream[A] extends AnyVal
- final class ZipVector[A] extends AnyVal
Value Members
- val IRWST: IndexedReaderWriterStateT.type
- val NonEmptyChain: NonEmptyChainImpl.type
- val NonEmptyMap: NonEmptyMapImpl.type
- val NonEmptySet: NonEmptySetImpl.type
-
def
NonEmptyStream[A](head: A, tail: A*): NonEmptyStream[A]
- Definition Classes
- ScalaVersionSpecificPackage
-
def
NonEmptyStream[A](head: A, tail: Stream[A] = Stream.empty): NonEmptyStream[A]
- Definition Classes
- ScalaVersionSpecificPackage
- val RWS: ReaderWriterState.type
- val RWST: ReaderWriterStateT.type
- val ReaderT: Kleisli.type
- object AndThen extends AndThenInstances0 with Serializable
- object AppFunc extends AppFuncInstances
- object Binested extends BinestedInstances with Serializable
- object Chain extends ChainInstances
- object Cokleisli extends CokleisliInstances with Serializable
- object Const extends ConstInstances with Serializable
- object Cont
- object ContT extends Serializable
- object EitherK extends EitherKInstances with Serializable
- object EitherT extends EitherTInstances with Serializable
- object Func extends FuncInstances
- object IdT extends IdTInstances with Serializable
- object IndexedReaderWriterStateT extends IRWSTInstances with CommonIRWSTConstructors with Serializable
- object IndexedState extends IndexedStateFunctions
- object IndexedStateT extends IndexedStateTInstances with CommonStateTConstructors0 with Serializable
- object Ior extends IorInstances with IorFunctions with IorFunctions2 with Serializable
- object IorT extends IorTInstances with Serializable
- object Kleisli extends KleisliInstances with KleisliFunctions with KleisliFunctionsBinCompat with KleisliExplicitInstances with Serializable
- object Nested extends NestedInstances with Serializable
- object NonEmptyList extends NonEmptyListInstances with Serializable
- object NonEmptySeq extends NonEmptySeqInstances with Serializable
- object NonEmptyVector extends NonEmptyVectorInstances with Serializable
- object OneAnd extends OneAndInstances with Serializable
- object Op extends OpInstances with Serializable
- object OptionT extends OptionTInstances with Serializable
- object Reader
- object ReaderWriterState extends RWSFunctions
- object ReaderWriterStateT extends RWSTFunctions
- object RepresentableStore extends Serializable
- object RepresentableStoreT extends RepresentableStoreTInstances1 with Serializable
- object State extends StateFunctions
- object StateT extends StateTFunctions with CommonStateTConstructors0
- object Store
- object StoreT
- object Tuple2K extends Tuple2KInstances with Serializable
- object Validated extends ValidatedInstances with ValidatedFunctions with ValidatedFunctionsBinCompat0 with Serializable
- object Writer
- object WriterT extends WriterTInstances with WriterTFunctions with WriterTFunctions0 with Serializable
-
object
ZipList
- Annotations
- @suppressUnusedImportWarningForScalaVersionSpecific()
-
object
ZipSeq
- Annotations
- @suppressUnusedImportWarningForScalaVersionSpecific()
- object ZipStream
-
object
ZipVector
- Annotations
- @suppressUnusedImportWarningForScalaVersionSpecific()