ArrowChoice

trait ArrowChoice[F[_, _]] extends Arrow[F] with Choice[F]

Must obey the laws defined in cats.laws.ArrowChoiceLaws.

Companion:
object
trait Choice[F]
trait Arrow[F]
trait Strong[F]
trait Profunctor[F]
trait Category[F]
trait Compose[F]
class Object
trait Matchable
class Any

Value members

Abstract methods

def choose[A, B, C, D](f: F[A, C])(g: F[B, D]): F[Either[A, B], Either[C, D]]

ArrowChoice yields Arrows with choice, allowing distribution over coproducts.

ArrowChoice yields Arrows with choice, allowing distribution over coproducts.

Given two Fs (f and g), create a new F with domain the coproduct of the domains of f and g, and codomain the coproduct of the codomains of f and g. This is the sum notion to split's product.

Example:

scala> import cats.implicits._
scala> val toLong: Int => Long = _.toLong
scala> val toDouble: Float => Double = _.toDouble
scala> val f: Either[Int, Float] => Either[Long, Double] = toLong +++ toDouble
scala> f(Left(3))
res0: Either[Long,Double] = Left(3)
scala> f(Right(3))
res1: Either[Long,Double] = Right(3.0)

Concrete methods

override def choice[A, B, C](f: F[A, C], g: F[B, C]): F[Either[A, B], C]
Definition Classes
def left[A, B, C](fab: F[A, B]): F[Either[A, C], Either[B, C]]
def right[A, B, C](fab: F[A, B]): F[Either[C, A], Either[C, B]]

Inherited methods

override def algebra[A]: Monoid[F[A, A]]
Definition Classes
Inherited from:
Category
override def algebraK: MonoidK[F]
Definition Classes
Inherited from:
Category
def andThen[A, B, C](f: F[A, B], g: F[B, C]): F[A, C]
Inherited from:
Compose
def codiagonal[A]: F[Either[A, A], A]

An F that, given a source A on either the right or left side, will return that same A object.

An F that, given a source A on either the right or left side, will return that same A object.

Example:

scala> import cats.implicits._
scala> val f: (Either[Int, Int]) => Int = Choice[Function1].codiagonal[Int]

scala> f(Right(3))
res0: Int = 3

scala> f(Left(3))
res1: Int = 3
Inherited from:
Choice
def compose[A, B, C](f: F[B, C], g: F[A, B]): F[A, C]
Inherited from:
Compose
override def dimap[A, B, C, D](fab: F[A, B])(f: C => A)(g: B => D): F[C, D]
Definition Classes
Inherited from:
Arrow
def first[A, B, C](fa: F[A, B]): F[(A, C), (B, C)]

Create a new F that takes two inputs, but only modifies the first input

Create a new F that takes two inputs, but only modifies the first input

Example:

scala> import cats.implicits._
scala> import cats.arrow.Strong
scala> val f: Int => Int = _ * 2
scala> val fab = Strong[Function1].first[Int,Int,Int](f)
scala> fab((2,3))
res0: (Int, Int) = (4,3)
Inherited from:
Strong
override def id[A]: F[A, A]
Definition Classes
Inherited from:
Arrow
def leftNarrow[A, B, AA <: A](fab: F[A, B]): F[AA, B]

Narrows A into a subtype AA. Example:

Narrows A into a subtype AA. Example:

scala> import cats.syntax.profunctor._
scala> import cats.instances.function._
scala>
scala> sealed trait Foo
scala> case object Bar extends Foo
scala> val x1: Foo => Int = _ => 1
scala> val x2: Bar.type => Int = x1.leftNarrow
Inherited from:
Profunctor
def lift[A, B](f: A => B): F[A, B]

Lift a function into the context of an Arrow.

Lift a function into the context of an Arrow.

In the reference articles "Arrows are Promiscuous...", and in the corresponding Haskell library Control.Arrow, this function is called arr.

Inherited from:
Arrow
def lmap[A, B, C](fab: F[A, B])(f: C => A): F[C, B]

contramap on the first type parameter

contramap on the first type parameter

Inherited from:
Profunctor
def merge[A, B, C](f: F[A, B], g: F[A, C]): F[A, (B, C)]

Create a new computation F that merge outputs of f and g both having the same input

Create a new computation F that merge outputs of f and g both having the same input

Example:

scala> import cats.implicits._
scala> val addEmpty: Int => Int = _ + 0
scala> val multiplyEmpty: Int => Double= _ * 1d
scala> val f: Int => (Int, Double) = addEmpty &&& multiplyEmpty
scala> f(1)
res0: (Int, Double) = (1,1.0)

Note that the arrow laws do not guarantee the non-interference between the effects of f and g in the context of F. This means that f &&& g may not be equivalent to g &&& f.

Inherited from:
Arrow
def rightWiden[A, B, BB >: B](fab: F[A, B]): F[A, BB]

Widens B into a supertype BB. Example:

Widens B into a supertype BB. Example:

scala> import cats.syntax.profunctor._
scala> import cats.instances.function._
scala>
scala> sealed trait Foo
scala> case object Bar extends Foo
scala> val x1: Int => Bar.type = _ => Bar
scala> val x2: Int => Foo = x1.rightWiden
Inherited from:
Profunctor
def rmap[A, B, C](fab: F[A, B])(f: B => C): F[A, C]

map on the second type parameter

map on the second type parameter

Inherited from:
Profunctor
override def second[A, B, C](fa: F[A, B]): F[(C, A), (C, B)]
Definition Classes
Inherited from:
Arrow
def split[A, B, C, D](f: F[A, B], g: F[C, D]): F[(A, C), (B, D)]

Create a new computation F that splits its input between f and g and combines the output of each.

Create a new computation F that splits its input between f and g and combines the output of each.

Example:

scala> import cats.implicits._
scala> import cats.arrow.Arrow
scala> val toLong: Int => Long = _.toLong
scala> val toDouble: Float => Double = _.toDouble
scala> val f: ((Int, Float)) => (Long, Double) = Arrow[Function1].split(toLong, toDouble)
scala> f((3, 4.0f))
res0: (Long, Double) = (3,4.0)

Note that the arrow laws do not guarantee the non-interference between the effects of f and g in the context of F. This means that f *** g may not be equivalent to g *** f.

Inherited from:
Arrow