Trait/Object

org.specs2.foldm

FoldM

Related Docs: object FoldM | package foldm

Permalink

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
Visibility
  1. Public
  2. All

Type Members

  1. abstract type S

    Permalink

Abstract Value Members

  1. abstract def end(s: S): M[U]

    Permalink
  2. abstract def fold: (S, T) ⇒ S

    Permalink
  3. abstract def start: M[S]

    Permalink

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    alias for observeNextState

  10. final def ==(arg0: Any): Boolean

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

    Permalink

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

  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def clone(): AnyRef

    Permalink
    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)] }

    Permalink

    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 }

    Permalink

    contramap the input values

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

    Permalink

    add an effectful action at the end of the fold

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

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

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

    Permalink
    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]) }

    Permalink

    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]) }

    Permalink

    first-like operator

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  24. def into[N[_]](implicit nat: ~>[M, N]): FoldM[T, N, U] { type S = FoldM.this.S }

    Permalink

    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

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

    Permalink

    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 }

    Permalink

    flatMap the output value

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

    Permalink
    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] }

    Permalink

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

  30. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  31. final def notifyAll(): Unit

    Permalink
    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) }

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    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 }

    Permalink

    map with another fold

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

    Permalink

    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]

    Permalink

    run over one element

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

    Permalink

    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]

    Permalink

    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) }

    Permalink

    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) }

    Permalink

    second-like operator

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

    Permalink

    add an effectful action at the beginning of the fold

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

    Permalink
    Definition Classes
    AnyRef
  44. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  45. def void(implicit m: Functor[M]): FoldM[T, M, Unit] { type S = FoldM.this.S }

    Permalink

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

  46. final def wait(): Unit

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

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

    Permalink
    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) }

    Permalink

    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