Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Aug 30, 2017
1 parent 0e9d119 commit d40c925
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ import simulacrum.typeclass
import cats.syntax.either._

def g(a: A, eval: Eval[Ior[NonEmptyList[B], NonEmptyList[C]]]): Eval[Ior[NonEmptyList[B], NonEmptyList[C]]] = {
val ior = eval.value
eval.map(ior =>
(f(a), ior) match {
case (Right(c), Ior.Left(_)) => Eval.now(ior.putRight(NonEmptyList.one(c)))
case (Right(c), _) => Eval.now(ior.map(c :: _))
case (Left(b), Ior.Right(r)) => Eval.now(Ior.bothNel(b, r))
case (Left(b), _) => Eval.now(ior.leftMap(b :: _))
}
case (Right(c), Ior.Left(_)) => ior.putRight(NonEmptyList.one(c))
case (Right(c), _) => ior.map(c :: _)
case (Left(b), Ior.Right(r)) => Ior.bothNel(b, r)
case (Left(b), _) => ior.leftMap(b :: _)
})
}

reduceRightTo(fa)(a => f(a).bimap(NonEmptyList.one, NonEmptyList.one).toIor)(g).value
Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/cats/tests/ReducibleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ abstract class ReducibleCheck[F[_]: Reducible: Functor](name: String)(implicit A
val g: Int => Either[Double, String] = f andThen Right.apply
val h: Int => Either[String, Double] = f andThen Left.apply

val withG = fi.partitionE(g).fold(_ => NonEmptyList.one(""), identity, (l,r) => r)
withG should === (Reducible[F].toNonEmptyList((fi.map(f))))
val withG = fi.partitionE(g).right.getOrElse(NonEmptyList.one(""))
withG should === (Reducible[F].toNonEmptyList(fi.map(f)))

val withH = fi.partitionE(h).fold(identity, _ => NonEmptyList.one(""), (l,r) => l)
withH should === (Reducible[F].toNonEmptyList((fi.map(f))))
val withH = fi.partitionE(h).left.getOrElse(NonEmptyList.one(""))
withH should === (Reducible[F].toNonEmptyList(fi.map(f)))
}
}

Expand Down

0 comments on commit d40c925

Please sign in to comment.