Skip to content

Commit

Permalink
typelevel#3141 [WIP] Implemented .reduceA
Browse files Browse the repository at this point in the history
  • Loading branch information
Twizty committed Nov 14, 2019
1 parent 2ce81ea commit ac9efdc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ import simulacrum.typeclass
def reduceLeftM[G[_], A, B](fa: F[A])(f: A => G[B])(g: (B, A) => G[B])(implicit G: FlatMap[G]): G[B] =
reduceLeftTo(fa)(f)((gb, a) => G.flatMap(gb)(g(_, a)))

/**
* Reduce a `F[G[A]]` value using `Applicative[G]` and `Semigroup[A]`, a universal
* semigroup for `G[_]`.
*
* This method is a generalization of `reduce`.
*/
def reduceA[G[_], A](fga: F[G[A]])(implicit G: Applicative[G], A: Semigroup[A]): G[A] =
reduceLeft(fga)((ga1, ga2) => G.map2(ga1, ga2)(A.combine))

/**
* Monadic reducing by mapping the `A` values to `G[B]`. combining
* the `B` values using the given `Semigroup[B]` instance.
Expand Down

0 comments on commit ac9efdc

Please sign in to comment.