Packages

sealed trait Fold[-I, +O] extends Serializable

Folds are first-class representations of "Traversable.foldLeft." They have the nice property that they can be fused to work in parallel over an input sequence.

A Fold accumulates inputs (I) into some internal type (X), converting to a defined output type (O) when done. We use existential types to hide internal details and to allow for internal and external (X and O) types to differ for "map" and "join."

In discussing this type we draw parallels to Function1 and related types. You can think of a fold as a function "Seq[I] => O" but in reality we do not have to materialize the input sequence at once to "run" the fold.

The traversal of the input data structure is NOT done by Fold itself. Instead we expose some methods like "overTraversable" that know how to iterate through various sequence types and drive the fold. We also expose some internal state so library authors can fold over their own types.

See the companion object for constructors.

Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Fold
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. abstract type X

    Users can ignore this type.

    Users can ignore this type.

    The internal accumulator type. No one outside this Fold needs to know what this is, and that's a good thing. It keeps type signatures sane and makes this easy to use for the amount of flexibility it provides.

Abstract Value Members

  1. abstract def build(): FoldState[X, I, O]

    Users can ignore this method.

    Users can ignore this method. It is exposed so library authors can run folds over their own sequence types.

    "build" constructs a FoldState, which tells us how to run the fold. It is expected that we can run the same Fold many times over different data structures, but we must build a new FoldState every time.

    See FoldState for information on how to use this for your own sequence types.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. def contramap[H](f: (H) => I): Fold[H, O]

    Transforms the input of the fold before every accumulation.

    Transforms the input of the fold before every accumulation. (The name comes from "contravariant map.") This is analogous to "Function1.andThen."

  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. def join[I2 <: I, P](other: Fold[I2, P]): Fold[I2, (O, P)]

    Convenient shorthand for joining Folds without combining at the end.

  14. def joinWith[I2 <: I, P, Q](other: Fold[I2, P])(f: (O, P) => Q): Fold[I2, Q]

    Joins two folds into one and combines the results.

    Joins two folds into one and combines the results. The fused fold accumulates with both at the same time and combines at the end.

  15. def map[P](f: (O) => P): Fold[I, P]

    Transforms the output of the Fold after iteration is complete.

    Transforms the output of the Fold after iteration is complete. This is analogous to "Future.map" or "Function1.compose."

  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. def overEmpty: O

    Trivially runs a Fold over an empty sequence.

  20. def overSingleton(i: I): O

    Trivially runs a Fold over a single element sequence.

  21. def overTraversable(is: TraversableOnce[I]): O

    Runs a Fold over a Traversable.

  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. def toString(): String
    Definition Classes
    AnyRef → Any
  24. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  26. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped