Skip to content

Commit

Permalink
Add choice syntax (#2315)
Browse files Browse the repository at this point in the history
* add choice syntax

* fix binary compatibility
  • Loading branch information
catostrophe authored and kailuowang committed Jul 9, 2018
1 parent 91ef0e9 commit a298890
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/arrow/Choice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import simulacrum.typeclass
* scala> import cats.implicits._
* scala> val b: Boolean => String = _ + " is a boolean"
* scala> val i: Int => String = _ + " is an integer"
* scala> val f: (Either[Boolean, Int]) => String = Choice[Function1].choice(b, i)
* scala> val f: (Either[Boolean, Int]) => String = b ||| i
*
* scala> f(Right(3))
* res0: String = 3 is an integer
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ trait AllSyntaxBinCompat0

trait AllSyntaxBinCompat1
extends FlatMapOptionSyntax
with ChoiceSyntax
with NestedSyntax
with BinestedSyntax
with ParallelFlatSyntax
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/scala/cats/syntax/choice.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cats
package syntax

import cats.arrow.Choice

trait ChoiceSyntax extends Choice.ToChoiceOps
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package object syntax {
object bitraverse extends BitraverseSyntax
@deprecated("use cats.syntax.semigroupal instead", "1.0.0-RC1")
object cartesian extends SemigroupalSyntax
object choice extends ChoiceSyntax
object coflatMap extends CoflatMapSyntax
object distributive extends DistributiveSyntax
object eitherK extends EitherKSyntax
Expand Down
3 changes: 2 additions & 1 deletion laws/src/main/scala/cats/laws/ChoiceLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cats
package laws

import cats.arrow.Choice
import cats.syntax.choice._
import cats.syntax.compose._

/**
Expand All @@ -11,7 +12,7 @@ trait ChoiceLaws[F[_, _]] extends CategoryLaws[F] {
implicit override def F: Choice[F]

def choiceCompositionDistributivity[A, B, C, D](fac: F[A, C], fbc: F[B, C], fcd: F[C, D]): IsEq[F[Either[A, B], D]] =
(F.choice(fac, fbc) andThen fcd) <-> F.choice(fac andThen fcd, fbc andThen fcd)
((fac ||| fbc) >>> fcd) <-> ((fac >>> fcd) ||| (fbc >>> fcd))
}

object ChoiceLaws {
Expand Down

0 comments on commit a298890

Please sign in to comment.