com.twitter.algebird

Fold

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
Learn more about member selection
Visibility
  1. Public
  2. All

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: AnyRef): Boolean

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

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

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

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

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

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

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

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

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

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. def join[I2 <: I, P](other: Fold[I2, P]): Fold[I2, (O, P)]

    Convenient shorthand for joining Folds without combining at the end.

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

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

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

    Definition Classes
    AnyRef
  19. final def notify(): Unit

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

    Definition Classes
    AnyRef
  21. def overEmpty: O

    Trivially runs a Fold over an empty sequence.

  22. def overSingleton(i: I): O

    Trivially runs a Fold over a single element sequence.

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

    Runs a Fold over a Traversable.

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

    Definition Classes
    AnyRef
  25. def toString(): String

    Definition Classes
    AnyRef → Any
  26. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped