Free

sealed abstract
class Free[S[_], A]

A free monad for a type constructor S. Binding is done using the heap instead of the stack, allowing tail-call elimination.

Companion
object
class Object
trait Matchable
class Any

Value members

Concrete methods

final
def >>=[B](f: A => Free[S, B]): Free[S, B]

Alias for flatMap

Alias for flatMap

final
def bounce(f: S[Free[S, A]] => Free[S, A])(implicit S: Functor[S]): Free[S, A]

Runs a single step, using a function that extracts the resumption from its suspension functor.

Runs a single step, using a function that extracts the resumption from its suspension functor.

def collect[B](implicit ev: Free[S, A] =:= Source[B, A]): (Vector[B], A)

Runs a Source all the way to the end, tail-recursively, collecting the produced values.

Runs a Source all the way to the end, tail-recursively, collecting the produced values.

def drain[E, B](source: Source[E, B])(implicit ev: Free[S, A] =:= Sink[E, A]): (A, B)

Feed the given source to this Sink.

Feed the given source to this Sink.

def drive[E, B](sink: Sink[Option[E], B])(implicit ev: Free[S, A] =:= Source[E, A]): (A, B)

Drive this Source with the given Sink.

Drive this Source with the given Sink.

def duplicateF: Free[[_] =>> Free[S, _$40], A]

Duplication in Free as a comonad in the endofunctor category.

Duplication in Free as a comonad in the endofunctor category.

def extendF[T[_]](f: NaturalTransformation[[_] =>> Free[S, _$44], T]): Free[T, A]

Extension in Free as a comonad in the endofunctor category.

Extension in Free as a comonad in the endofunctor category.

def extractF(implicit S: Monad[S]): S[A]

Extraction from Free as a comonad in the endofunctor category.

Extraction from Free as a comonad in the endofunctor category.

def feed[E](ss: Stream[E])(implicit ev: Free[S, A] =:= Sink[E, A]): A

Feed the given stream to this Source.

Feed the given stream to this Source.

final
def flatMap[B](f: A => Free[S, B]): Free[S, B]

Binds the given continuation to the result of this computation.

Binds the given continuation to the result of this computation.

final
def flatMapSuspension[T[_]](f: NaturalTransformation[S, [_] =>> Free[T, _$24]]): Free[T, A]

Substitutes a free monad over the given functor into the suspension functor of this program. Free is a monad in an endofunctor category and this is its monadic bind.

Substitutes a free monad over the given functor into the suspension functor of this program. Free is a monad in an endofunctor category and this is its monadic bind.

final
def fold[B](r: A => B, s: S[Free[S, A]] => B)(implicit S: Functor[S]): B

Catamorphism. Run the first given function if Return, otherwise, the second given function.

Catamorphism. Run the first given function if Return, otherwise, the second given function.

final
def foldMap[M[_]](f: NaturalTransformation[S, M])(implicit M: Monad[M]): M[A]

Catamorphism for Free. Runs to completion, mapping the suspension with the given transformation at each step and accumulating into the monad M.

Catamorphism for Free. Runs to completion, mapping the suspension with the given transformation at each step and accumulating into the monad M.

final
def foldMapRec[M[_]](f: NaturalTransformation[S, M])(implicit M: Applicative[M], B: BindRec[M]): M[A]
final
def foldRight[G[_]](z: NaturalTransformation[Id, G])(f: NaturalTransformation[[α] =>> S[G[α]], G])(implicit S: Functor[S]): G[A]

Folds this free recursion to the right using the given natural transformations.

Folds this free recursion to the right using the given natural transformations.

final
def foldRun[B](b: B)(f: (B, S[Free[S, A]]) => (B, Free[S, A]))(implicit S: Functor[S]): (B, A)

Runs to completion, allowing the resumption function to thread an arbitrary state of type B.

Runs to completion, allowing the resumption function to thread an arbitrary state of type B.

final
def foldRunM[M[_], B](b: B)(f: NaturalTransformation[[α] =>> (B, S[α]), [α] =>> M[(B, α)]])(implicit M0: Applicative[M], M1: BindRec[M]): M[(B, A)]

Variant of foldRun that allows to interleave effect M at each step.

Variant of foldRun that allows to interleave effect M at each step.

final
def go(f: S[Free[S, A]] => Free[S, A])(implicit S: Functor[S]): A

Runs to completion, using a function that extracts the resumption from its suspension functor.

Runs to completion, using a function that extracts the resumption from its suspension functor.

final
def map[B](f: A => B): Free[S, B]
final

Modifies the first suspension with the given natural transformation.

Modifies the first suspension with the given natural transformation.

final
def mapSuspension[T[_]](f: NaturalTransformation[S, T]): Free[T, A]

Changes the suspension functor by the given natural transformation.

Changes the suspension functor by the given natural transformation.

@tailrec
final
def resume(implicit S: Functor[S]): S[Free[S, A]] \/ A

Evaluates a single layer of the free monad *

Evaluates a single layer of the free monad *

final
def run(implicit ev: Free[S, A] =:= Trampoline[A]): A

Runs a trampoline all the way to the end, tail-recursively.

Runs a trampoline all the way to the end, tail-recursively.

final
def runM[M[_]](f: S[Free[S, A]] => M[Free[S, A]])(implicit S: Functor[S], M: Monad[M]): M[A]

Runs to completion, using a function that maps the resumption from S to a monad M.

Runs to completion, using a function that maps the resumption from S to a monad M.

Since

7.0.1

final
def runRecM[M[_]](f: S[Free[S, A]] => M[Free[S, A]])(implicit S: Functor[S], M: Applicative[M], B: BindRec[M]): M[A]

Run Free using constant stack.

Run Free using constant stack.

@tailrec
final
def step: Free[S, A]

Evaluate one layer in the free monad, re-associating any left-nested binds to the right and pulling the first suspension to the top.

Evaluate one layer in the free monad, re-associating any left-nested binds to the right and pulling the first suspension to the top.

def toFreeT(implicit S: Functor[S]): FreeT[S, Id, A]
final
def zap[G[_], B](fs: Cofree[G, A => B])(implicit S: Functor[S], d: Zap[S, G]): B

Applies a function in a comonad to the corresponding value in this monad, annihilating both.

Applies a function in a comonad to the corresponding value in this monad, annihilating both.

final
def zapWith[G[_], B, C](bs: Cofree[G, B])(f: (A, B) => C)(implicit S: Functor[S], d: Zap[S, G]): C

Applies a function f to a value in this monad and a corresponding value in the dual comonad, annihilating both.

Applies a function f to a value in this monad and a corresponding value in the dual comonad, annihilating both.

final
def zipWith[B, C](tb: Free[S, B])(f: (A, B) => C): Free[S, C]

Interleave this computation with another, combining the results with the given function.

Interleave this computation with another, combining the results with the given function.