Fold

trait Fold[M[_], A, B]

A Fold is a "left fold" over a data structure with:

  • a 'start' value
  • a 'fold' method to accumulate state
  • an 'end' method to finalize the result

Both 'start' and 'end' have an effect which allows the whole folding to take place inside a context.

Companion:
object
class Object
trait Matchable
class Any
Fold[M, A, B]

Type members

Types

type S

Value members

Abstract methods

def end(s: S): M[B]
def fold: (S, A) => M[S]
def monad: Monad[M]
def start: M[S]

Concrete methods

def &&&[C](f: Fold[M, A, C]): Fold[M, A, (B, C)]

fanout = zip in the Arrow terminology

fanout = zip in the Arrow terminology

def ***[V, W](f: Fold[M, V, W]): Fold[M, (A, V), (B, W)]

parallel composition

parallel composition

def *>[C](f: Fold[M, A, C]): Fold[M, A, C]

zip with another fold, running this one only for its side effects

zip with another fold, running this one only for its side effects

def <*[C](f: Fold[M, A, C]): Fold[M, A, B]

zip with another fold only for its side effects

zip with another fold only for its side effects

def <*>[C](f: Fold[M, A, C]): Fold[M, A, (B, C)]

zip 2 folds to return a pair of values. alias for zip

zip 2 folds to return a pair of values. alias for zip

def <+*(sink: Sink[M, S]): Fold[M, A, B]

alias for observeNextState

alias for observeNextState

def <-*(sink: Sink[M, S]): Fold[M, A, B]

alias for observeState

alias for observeState

def <<+*(sink: Sink[M, (A, S)]): Fold[M, A, B]

alias for observeWithNextState

alias for observeWithNextState

def <<-*(sink: Sink[M, (A, S)]): Fold[M, A, B]

alias for observeWithState

alias for observeWithState

def as[C](c: => C): Fold[M, A, C]

equivalent of the as method for functors, added here for easier type inference

equivalent of the as method for functors, added here for easier type inference

def compose[C](f2: Fold[M, B, C]): Fold[M, A, C]

pipe the output of this fold into another fold

pipe the output of this fold into another fold

def contraflatMap[C](f: C => M[A]): Fold[M, C, B]

contramap the input values with effects

contramap the input values with effects

def contramap[C](f: C => A): Fold[M, C, B]

contramap the input values

contramap the input values

def endWith(action: M[Unit]): Fold[M, A, B] { type S = S; }
def into[M1[_]](using nat: NaturalTransformation[M, M1], m: Monad[M1]): Fold[M1, A, B] { type S = S; }
def map[C](f: B => C): Fold[M, A, C]

map the output value

map the output value

def mapFlatten[C](f: B => M[C]): Fold[M, A, C]

flatMap the output value

flatMap the output value

def monadic[M1[_]](using nat: NaturalTransformation[M, M1], m: Monad[M1]): Fold[M1, A, B] { type S = S; }
def nest[F[_], C](f: C => F[A])(using monoid: Monoid[B], foldable: Foldable[F]): Fold[M, C, B]

create a fold that will run this fold repeatedly on input elements and collect all results

create a fold that will run this fold repeatedly on input elements and collect all results

def observe[C](f: Fold[M, A, C]): Fold[M, A, B]

alias for <*

alias for <*

def observeNextState(sink: Sink[M, S]): Fold[M, A, B]

observe the next state

observe the next state

def observeState(sink: Sink[M, S]): Fold[M, A, B]

observe the current state

observe the current state

def observeWithNextState(sink: Sink[M, (A, S)]): Fold[M, A, B]

observe both the input value and the next state

observe both the input value and the next state

def observeWithState(sink: Sink[M, (A, S)]): Fold[M, A, B]

observe both the input value and the current state

observe both the input value and the current state

def observedBy[C](f: Fold[M, A, C]): Fold[M, A, C]

alias for *>

alias for *>

def pipe[C](f: Fold[M, B, C]): Fold[M, A, C]

run another fold on the end result

run another fold on the end result

def run[F[_]](foldable: F[A])(using evidence$1: Foldable[F]): M[B]

run a Fold with a Foldable instance

run a Fold with a Foldable instance

def run1(a: A): M[B]

run over one element

run over one element

def startWith(action: M[Unit]): Fold[M, A, B] { type S = S; }
def void: Fold[M, A, Unit]

equivalent of the void method for functors, added here for easier type inference

equivalent of the void method for functors, added here for easier type inference

def zip[C](f: Fold[M, A, C]): Fold[M, A, (B, C)] { type S = (S, S); }

zip 2 folds to return a pair of values. alias for <*>

zip 2 folds to return a pair of values. alias for <*>

Givens

Givens

given given_Monad_M: Monad[M]