Left associative fold on 'F' using the function 'f'.
Left associative fold on 'F' using the function 'f'.
Right associative lazy fold on F
using the folding function 'f'.
Right associative lazy fold on F
using the folding function 'f'.
This method evaluates lb
lazily (in some cases it will not be
needed), and returns a lazy value. We are using (A, Eval[B]) =>
Eval[B]
to support laziness in a stack-safe way. Chained
computation should be performed via .map and .flatMap.
For more detailed information about how this method works see the
documentation for Eval[_]
.
Given a function which returns a G effect, thread this effect through the running of this function on all the values in F, returning an F[B] in a G context.
Replaces the A
value in F[A]
with the supplied value.
Replaces the A
value in F[A]
with the supplied value.
Alias for fold.
Compose this Foldable[F]
with a Foldable[G]
to create
a Foldable[F[G]]
instance.
Compose this Foldable[F]
with a Foldable[G]
to create
a Foldable[F[G]]
instance.
Compose this functor F with a functor G to produce a composite Functor on G[F[_]], with a map method which uses an A => B to map a G[F[A]] to a G[F[B]].
Compose this functor F with a functor G to produce a composite Functor on G[F[_]], with a map method which uses an A => B to map a G[F[A]] to a G[F[B]].
Compose 2 invariant Functors F and G to get a new Invariant Functor for F[G[_]].
Compose 2 invariant Functors F and G to get a new Invariant Functor for F[G[_]].
Compose this functor F with a Contravariant Functor G to produce a new Contravariant Functor on F[G[_]].
Compose the Invariant Functor F with a normal (Covariant) Functor to get a new Invariant Functor for [F[G[_]].
Convert F[A] to a List[A], dropping all initial elements which
match p
.
Convert F[A] to a List[A], dropping all initial elements which
match p
.
Check whether at least one element satisfies the predicate.
Check whether at least one element satisfies the predicate.
If there are no elements, the result is false
.
Convert F[A] to a List[A], only including elements which match p
.
Convert F[A] to a List[A], only including elements which match p
.
Find the first element matching the predicate, if one exists.
Find the first element matching the predicate, if one exists.
Fold implemented using the given Monoid[A] instance.
Fold implemented using the given Monoid[A] instance.
Fold implemented using the given MonoidK[G]
instance.
Fold implemented using the given MonoidK[G]
instance.
This method is identical to fold, except that we use the universal monoid (MonoidK[G]
)
to get a Monoid[G[A]]
instance.
For example:
val F = Foldable[List] F.foldK(List(1 :: 2 :: Nil, 3 :: 4 :: 5 :: Nil)) // List(1, 2, 3, 4, 5)
Fold implemented by mapping A
values into B
and then
combining them using the given Monoid[B]
instance.
Fold implemented by mapping A
values into B
and then
combining them using the given Monoid[B]
instance.
Check whether all elements satisfy the predicate.
Check whether all elements satisfy the predicate.
If there are no elements, the result is true
.
Tuple the values in fa with the result of applying a function with the value
Tuple the values in fa with the result of applying a function with the value
Returns true if there are no elements.
Returns true if there are no elements. Otherwise false.
Lift a function f to operate on Functors
Lift a function f to operate on Functors
Thread all the G effects through the F structure to invert the structure from F[G[A]] to G[F[A]].
Behaves just like sequence, but uses Unapply to find the Applicative instance for G.
Sequence F[G[A]]
using Applicative[G]
.
Sequence F[G[A]]
using Applicative[G]
.
This is similar to traverse_
except it operates on F[G[A]]
values, so no additional functions are needed.
For example:
val F = Foldable[List] F.sequence_(List(Option(1), Option(2), Option(3))) // Some(()) F.sequence_(List(Option(1), None, Option(3))) // None
Convert F[A] to a List[A].
Convert F[A] to a List[A].
Behaves just like traverse, but uses Unapply to find the Applicative instance for G.
Traverse F[A]
using Applicative[G]
.
Traverse F[A]
using Applicative[G]
.
A
values will be mapped into G[B]
and combined using
Applicative#map2
.
For example:
def parseInt(s: String): Option[Int] = ... val F = Foldable[List] F.traverse_(List("333", "444"))(parseInt) // Some(()) F.traverse_(List("333", "zzz"))(parseInt) // None
This method is primarily useful when G[_]
represents an action
or effect, and the specific A
aspect of G[A]
is not otherwise
needed.
Empty the fa of the values, preserving the structure
Empty the fa of the values, preserving the structure
Traverse, also known as Traversable.
Traversal over a structure with an effect.
Traversing with the cats.Id effect is equivalent to cats.Functor#map. Traversing with the cats.data.Const effect where the first type parameter has a cats.Monoid instance is equivalent to cats.Foldable#fold.
See: The Essence of the Iterator Pattern