Foldable

trait Foldable[F[_]]

Inspired from the scalaz (https://github.com/scalaz/scalaz) project

Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def foldLeft[A, B](fa: F[A], z: B)(f: (B, A) => B): B

Left-associative fold of a structure.

Left-associative fold of a structure.

def foldMap[A, B](fa: F[A])(f: A => B)(using F: Monoid[B]): B

Map each element of the structure to a Monoid, and combine the results.

Map each element of the structure to a Monoid, and combine the results.

def foldRight[A, B](fa: F[A], z: => B)(f: (A, => B) => B): B

Right-associative fold of a structure.

Right-associative fold of a structure.

Concrete methods

def all[A](fa: F[A])(p: A => Boolean): Boolean

Whether all As in fa yield true from p.

Whether all As in fa yield true from p.

def allM[G[_], A](fa: F[A])(p: A => G[Boolean])(using G: Monad[G]): G[Boolean]

all with monadic traversal.

all with monadic traversal.

def any[A](fa: F[A])(p: A => Boolean): Boolean

Whether any As in fa yield true from p.

Whether any As in fa yield true from p.

def anyM[G[_], A](fa: F[A])(p: A => G[Boolean])(using G: Monad[G]): G[Boolean]

any with monadic traversal.

any with monadic traversal.

final def count[A](fa: F[A]): Int

Alias for length.

Alias for length.

def empty[A](fa: F[A]): Boolean

Deforested alias for toStream(fa).isEmpty.

Deforested alias for toStream(fa).isEmpty.

def findLeft[A](fa: F[A])(f: A => Boolean): Option[A]
def findRight[A](fa: F[A])(f: A => Boolean): Option[A]
def fold[M](t: F[M])(using evidence$1: Monoid[M]): M

Combine the elements of a structure using a monoid.

Combine the elements of a structure using a monoid.

def foldLeftM[G[_], A, B](fa: F[A], z: B)(f: (B, A) => G[B])(using M: Monad[G]): G[B]

Left-associative, monadic fold of a structure.

Left-associative, monadic fold of a structure.

def foldMapM[G[_], A, B](fa: F[A])(f: A => G[B])(using B: Monoid[B], G: Monad[G]): G[B]

Specialization of foldRightM when B has a Monoid.

Specialization of foldRightM when B has a Monoid.

def foldRightM[G[_], A, B](fa: F[A], z: => B)(f: (A, => B) => G[B])(using M: Monad[G]): G[B]

Right-associative, monadic fold of a structure.

Right-associative, monadic fold of a structure.

def index[A](fa: F[A], i: Int): Option[A]
Returns:

the element at index i in a Some, or None if the given index falls outside of the range

def indexOr[A](fa: F[A], default: => A, i: Int): A
Returns:

the element at index i, or default if the given index falls outside of the range

def intercalate[A](fa: F[A], a: A)(using A: Monoid[A]): A

Insert an A between every A, yielding the sum.

Insert an A between every A, yielding the sum.

def length[A](fa: F[A]): Int

Deforested alias for toStream(fa).size.

Deforested alias for toStream(fa).size.

def sequence_[M[_], A](fa: F[M[A]])(using a: Applicative[M]): M[Unit]

Strict sequencing in an applicative functor M that ignores the value in fa.

Strict sequencing in an applicative functor M that ignores the value in fa.

def suml[A](fa: F[A])(using A: Monoid[A]): A
def sumr[A](fa: F[A])(using A: Monoid[A]): A
def toList[A](fa: F[A]): List[A]
def toSet[A](fa: F[A]): Set[A]
def toStream[A](fa: F[A]): LazyList[A]
def toVector[A](fa: F[A]): Vector[A]
def traverse_[M[_], A, B](fa: F[A])(f: A => M[B])(using a: Applicative[M]): M[Unit]

Strict traversal in an applicative functor M that ignores the result of f.

Strict traversal in an applicative functor M that ignores the result of f.