trait FoldM[T, M[_], U] extends AnyRef
A FoldM is a "left fold" over a data structure with:
- a 'start' value
- a 'fold' method to accumulate state
- an 'end' method to finalize the result
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:
- 'sum' computes the sum of some elements
- 'list' accumulates all the elements in a list
- the 'sum compose list' will accumulate the list of all the sums over some elements (this is a 'scan')
A FoldM can be used with a 'FoldableM' which produces the elements to fold over. Examples of FoldableM include
- a List
- an Iterator
- a scalaz Process
Usage example:
sum.run(List(1, 2, 3)) == 6
- Self Type
- FoldM[T, M, U]
- Alphabetic
- By Inheritance
- FoldM
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- abstract type S
Abstract Value Members
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
&&&[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }
fanout = zip in the Arrow terminology
-
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) }
parallel composition
-
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) }
zip on the right with another fold only for self side-effects
-
def
<*[V](f: SinkM[T, M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, f.S) }
zip with another fold only for its side effects
-
def
<*>[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }
zip 2 folds to return a pair of values.
zip 2 folds to return a pair of values. alias for zip
-
def
<<*[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }
alias for observeState
-
def
<<<*[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }
alias for observeNextState
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
as[V](v: ⇒ V)(implicit m: Functor[M]): FoldM[T, M, V] { type S = FoldM.this.S }
equivalent of the as method for functors, added here for easier type inference
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
compose[V](f2: FoldM[U, M, V])(implicit m: Monad[M]): FoldM[T, M, V] { type S = M[(FoldM.this.S, f2.S)] }
pipe the output of this fold into another fold
-
def
contramap[R](f: (R) ⇒ T)(implicit m: Functor[M]): FoldM[R, M, U] { type S = FoldM.this.S }
contramap the input values
-
def
endWith(action: M[Unit])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = FoldM.this.S }
add an effectful action at the end of the fold
-
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] )
-
def
first[V](implicit m: MonadPlus[M]): FoldM[(T, V), M, (U, V)] { type S = (FoldM.this.S, M[V]) }
first operator on a MonadPlus monad
-
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]) }
first-like operator
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
def
into[N[_]](implicit nat: ~>[M, N]): FoldM[T, N, U] { type S = FoldM.this.S }
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)
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map[V](f: (U) ⇒ V)(implicit m: Functor[M]): FoldM[T, M, V] { type S = FoldM.this.S }
map the output value
-
def
mapFlatten[V](f: (U) ⇒ M[V])(implicit m: Bind[M]): FoldM[T, M, V] { type S = FoldM.this.S }
flatMap the output value
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
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] }
create a fold that will run this fold repeatedly on input elements and collect all results
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
observe[V](f: SinkM[T, M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, f.S) }
alias for <*
-
def
observeNextState[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }
observe both the input value and the next state
-
def
observeState[V](sink: SinkM[(S, T), M])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = (FoldM.this.S, sink.S) }
observe both the input value and the current state
-
def
pipe[V](f: FoldM[U, M, V])(implicit m: Bind[M]): FoldM[T, M, V] { type S = FoldM.this.S }
map with another fold
-
def
run[F[_]](ft: F[T])(implicit foldableM: FoldableM[F, M]): M[U]
run a FoldM with a FoldableM instance (like a List, an Iterator, a scalaz Process)
-
def
run1(t: T)(implicit m: Bind[M]): M[U]
run over one element
-
def
runBreak[F[_]](ft: F[T])(implicit foldableM: FoldableM[F, M]): M[U]
run a FoldM with a FoldableM instance (like a List, an Iterator, a scalaz Process) and break early if possible
-
def
runS[F](f: F)(implicit foldableMS: FoldableMS[T, F, M]): M[U]
run a FoldM with a FoldableMS instance (like an InputStream which is specialized on producing Array[Byte])
-
def
second[V](implicit m: MonadPlus[M]): FoldM[(V, T), M, (V, U)] { type S = (M[V], FoldM.this.S) }
second operator on a MonadPlus monad
-
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) }
second-like operator
-
def
startWith(action: M[Unit])(implicit ap: Apply[M]): FoldM[T, M, U] { type S = FoldM.this.S }
add an effectful action at the beginning of the fold
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
void(implicit m: Functor[M]): FoldM[T, M, Unit] { type S = FoldM.this.S }
equivalent of the void method for functors, added here for easier type inference
-
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( ... )
-
def
zip[V](f: FoldM[T, M, V])(implicit ap: Apply[M]): FoldM[T, M, (U, V)] { type S = (FoldM.this.S, f.S) }
zip 2 folds to return a pair of values.
zip 2 folds to return a pair of values. alias for <*>