Packages

trait FoldM[T, M[_], U] extends AnyRef

A FoldM 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 M.

If 'M' has an 'Apply' instance then FoldM can be made Applicative to allow the folding of two values U and S at the same time.

If 'M' has a 'Monad' instance then FoldM can be made into a 'Compose' instance which allows to compose 2 folds into one, for example:

  • 'sum' computes the sum of some elements
  • 'list' accumulates all the elements in a list
  • the 'sum compose list' will accumulate the list of all the sums over some elements (this is a 'scan')

A FoldM can be used with a 'FoldableM' which produces the elements to fold over. Examples of FoldableM include

  • a List
  • an Iterator
  • a scalaz Process

Usage example:

sum.run(List(1, 2, 3)) == 6

Self Type
FoldM[T, M, U]
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FoldM
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type S

Abstract Value Members

  1. abstract def end(s: S): M[U]
  2. abstract def fold: (S, T) ⇒ S
  3. abstract def start: M[S]

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def &&&[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }

    fanout = zip in the Arrow terminology

  4. def ***[V, W](f: FoldM[V, M, W])(implicit m: Bind[M]): FoldM[(T, V), M, (U, W)] { type S = (FoldM.this.S, f.S) }

    parallel composition

  5. def *>[V](f: FoldM[T, M, V])(implicit ap: Apply[M], ev: <:<[U, Unit]): FoldM[T, M, V] { type S = (FoldM.this.S, f.S) }

    zip on the right with another fold only for self side-effects

  6. def <*[V](f: SinkM[T, M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, f.S) }

    zip with another fold only for its side effects

  7. def <*>[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }

    zip 2 folds to return a pair of values.

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

  8. def <<*[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }

    alias for observeState

  9. def <<<*[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }

    alias for observeNextState

  10. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  11. def as[V](v: ⇒ V)(implicit m: Functor[M]): FoldM[T, M, V] { type S = FoldM.this.S }

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

  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def compose[V](f2: FoldM[U, M, V])(implicit m: Monad[M]): FoldM[T, M, V] { type S = M[(FoldM.this.S, f2.S)] }

    pipe the output of this fold into another fold

  15. def contramap[R](f: (R) ⇒ T)(implicit m: Functor[M]): FoldM[R, M, U] { type S = FoldM.this.S }

    contramap the input values

  16. def endWith(action: M[Unit])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = FoldM.this.S }

    add an effectful action at the end of the fold

  17. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  19. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. def first[V](implicit m: MonadPlus[M]): FoldM[(T, V), M, (U, V)] { type S = (FoldM.this.S, M[V]) }

    first operator on a MonadPlus monad

  21. def firstOption[V](implicit m: Bind[M], nat: ~>[scalaz.Id.Id, M]): FoldM[(T, V), M, (U, Option[V])] { type S = (FoldM.this.S, Option[V]) }

    first-like operator

  22. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  24. def into[N[_]](implicit nat: ~>[M, N]): FoldM[T, N, U] { type S = FoldM.this.S }

    use a natural transformation to go from context M to context N this can be used to transform a FoldM[A, Id, B] into a FoldM[A, Task, B] for example (a fold with no effects to a fold with monadic effects from the Task monad)

  25. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  26. def map[V](f: (U) ⇒ V)(implicit m: Functor[M]): FoldM[T, M, V] { type S = FoldM.this.S }

    map the output value

  27. def mapFlatten[V](f: (U) ⇒ M[V])(implicit m: Bind[M]): FoldM[T, M, V] { type S = FoldM.this.S }

    flatMap the output value

  28. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. def nest[F[_], R](f: (R) ⇒ F[T])(implicit df: FoldableM[F, M], monoid: Monoid[U], monad: Monad[M]): FoldM[R, M, U] { type S = M[U] }

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

  30. final def notify(): Unit
    Definition Classes
    AnyRef
  31. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  32. def observe[V](f: SinkM[T, M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, f.S) }

    alias for <*

  33. def observeNextState[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }

    observe both the input value and the next state

  34. def observeState[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }

    observe both the input value and the current state

  35. def pipe[V](f: FoldM[U, M, V])(implicit m: Bind[M]): FoldM[T, M, V] { type S = FoldM.this.S }

    map with another fold

  36. def run[F[_]](ft: F[T])(implicit foldableM: FoldableM[F, M]): M[U]

    run a FoldM with a FoldableM instance (like a List, an Iterator, a scalaz Process)

  37. def run1(t: T)(implicit m: Bind[M]): M[U]

    run over one element

  38. def runBreak[F[_]](ft: F[T])(implicit foldableM: FoldableM[F, M]): M[U]

    run a FoldM with a FoldableM instance (like a List, an Iterator, a scalaz Process) and break early if possible

  39. def runS[F](f: F)(implicit foldableMS: FoldableMS[T, F, M]): M[U]

    run a FoldM with a FoldableMS instance (like an InputStream which is specialized on producing Array[Byte])

  40. def second[V](implicit m: MonadPlus[M]): FoldM[(V, T), M, (V, U)] { type S = (M[V], FoldM.this.S) }

    second operator on a MonadPlus monad

  41. def secondOption[V](implicit m: Bind[M], nat: ~>[scalaz.Id.Id, M]): FoldM[(V, T), M, (Option[V], U)] { type S = (Option[V], FoldM.this.S) }

    second-like operator

  42. def startWith(action: M[Unit])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = FoldM.this.S }

    add an effectful action at the beginning of the fold

  43. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  44. def toString(): String
    Definition Classes
    AnyRef → Any
  45. def void(implicit m: Functor[M]): FoldM[T, M, Unit] { type S = FoldM.this.S }

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

  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. def zip[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }

    zip 2 folds to return a pair of values.

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

Inherited from AnyRef

Inherited from Any

Ungrouped