Template trait to define Foldable
in terms of foldMap
.
Template trait to define Foldable
in terms of foldMap
.
Example:
new Foldable[Option] with Foldable.FromFoldMap[Option] { def foldMap[A, B](fa: Option[A])(f: A => B)(implicit F: Monoid[B]) = fa match { case Some(a) => f(a) case None => F.zero } }
Template trait to define Foldable
in terms of foldRight
Template trait to define Foldable
in terms of foldRight
Example:
new Foldable[Option] with Foldable.FromFoldr[Option] { def foldRight[A, B](fa: Option[A], z: B)(f: (A, => B) => B) = fa match { case Some(a) => f(a, z) case None => z } }