Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add choice syntax #2315

Merged
merged 2 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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