org.specs2.foldm

FoldM

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

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

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:

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

Usage example:

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

Self Type
FoldM[T, M, U]
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. FoldM
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
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: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  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 observeState

  10. 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

  11. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  13. 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

  14. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  15. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  16. 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

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

    contramap the input values

  18. 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

  19. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  21. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. 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

  23. 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

  24. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  25. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  26. 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)

  27. final def isInstanceOf[T0]: Boolean

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

    map the output value

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

    flatMap the output value

  30. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  31. 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

  32. final def notify(): Unit

    Definition Classes
    AnyRef
  33. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  34. def observe[V](f: SinkM[T, M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, f.S) }

    alias for <*

  35. 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

  36. 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

  37. 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

  38. 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)

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

    run over one element

  40. 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

  41. 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])

  42. 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

  43. 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

  44. 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

  45. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  46. def toString(): String

    Definition Classes
    AnyRef → Any
  47. 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

  48. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. 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