Trait/Object

com.twitter.algebird

Fold

Related Docs: object Fold | package algebird

Permalink

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

Type Members

  1. abstract type X

    Permalink

    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]

    Permalink

    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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def contramap[H](f: (H) ⇒ I): Fold[H, O]

    Permalink

    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

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

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

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

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

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

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

    Permalink

    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]

    Permalink

    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]

    Permalink

    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

    Permalink
    Definition Classes
    AnyRef
  17. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  19. def overEmpty: O

    Permalink

    Trivially runs a Fold over an empty sequence.

  20. def overSingleton(i: I): O

    Permalink

    Trivially runs a Fold over a single element sequence.

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

    Permalink

    Runs a Fold over a Traversable.

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped