Skip to content

Commit

Permalink
Add doc tests and note in docs for map + separate
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Aug 30, 2017
1 parent 81de760 commit d00a55f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,16 @@ import simulacrum.typeclass

/**
* Separate this Foldable into a Tuple by a separating function `A => Either[B, C]`
* Equivalent to `Functor#map` and then `Alternative#separate`
*
* {{{
* scala> import cats.implicits._
* scala> val list = List(1,2,3,4)
* scala> Foldable[List].partitionEither(list)(a => if (a % 2 == 0) Left(a.toString) else Right(a))
* res0: (List[String], List[Int]) = (List(2, 4),List(1, 3))
* scala> Foldable[List].partitionEither(list)(a => Right(a * 4))
* res1: (List[Nothing], List[Int]) = (List(),List(4, 8, 12, 16))
* }}}
*/
def partitionEither[A, B, C](fa: F[A])(f: A => Either[B, C])(implicit A: Alternative[F]): (F[B], F[C]) = {
import cats.instances.tuple._
Expand Down

0 comments on commit d00a55f

Please sign in to comment.