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.
- Alphabetic
- By Inheritance
- Fold
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
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
-
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
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
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."
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
join[I2 <: I, P](other: Fold[I2, P]): Fold[I2, (O, P)]
Convenient shorthand for joining Folds without combining at the end.
-
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.
-
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."
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
overEmpty: O
Trivially runs a Fold over an empty sequence.
-
def
overSingleton(i: I): O
Trivially runs a Fold over a single element sequence.
-
def
overTraversable(is: TraversableOnce[I]): O
Runs a Fold over a Traversable.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )