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 foldr
Template trait to define Foldable
in terms of foldr
Example:
new Foldable[Option] with Foldable.FromFoldr[Option] { def foldr[A, B](fa: Option[A], z: B)(f: (A) => (=> B) => B) = fa match { case Some(a) => f(a)(z) case None => z } }