Skip to content

Instantly share code, notes, and snippets.

@slouc
Created July 19, 2019 12:25
Show Gist options
  • Save slouc/fa292cc3714317c823de746fd4bdf7fd to your computer and use it in GitHub Desktop.
Save slouc/fa292cc3714317c823de746fd4bdf7fd to your computer and use it in GitHub Desktop.
import cats._
import cats.implicits._
def foo1[A, B: Semigroup, F[_]: Traverse: Reducible, G[_]: Applicative](
fa: F[A],
fun: A => G[B]
): G[B] =
Traverse[F].traverse(fa)(fun).map(Reducible[F].reduce[B])
// foo2 doesn't need F to be Traverse, but needs G to be FlatMap
def foo2[A, B: Semigroup, F[_]: Reducible, G[_]: FlatMap](
fa: F[A],
fun: A => G[B]
): G[B] =
Reducible[F].reduceMapM(fa)(fun)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment