Collapse the structure with a left-associative function
Collapse the structure with a left-associative function
Collapse the structure by mapping each element to an element of a type that has a cats.Monoid
Collapse the structure by mapping each element to an element of a type that has a cats.Monoid
Collapse the structure with a right-associative function
Collapse the structure with a right-associative function
The quintessential method of the Bifunctor trait, it applies a function to each "side" of the bifunctor.
The quintessential method of the Bifunctor trait, it applies a function to each "side" of the bifunctor.
Example:
scala> import cats.implicits._ scala> val x: (List[String], Int) = (List("foo", "bar"), 3) scala> x.bimap(_.headOption, _.toLong + 1) res0: (Option[String], Long) = (Some(foo),4)
Invert the structure from F[G[A], G[B]] to G[F[A, B]].
Invert the structure from F[G[A], G[B]] to G[F[A, B]].
Example:
scala> import cats.implicits._ scala> val rightSome: Either[Option[String], Option[Int]] = Either.right(Some(3)) scala> rightSome.bisequence res0: Option[Either[String, Int]] = Some(Right(3)) scala> val rightNone: Either[Option[String], Option[Int]] = Either.right(None) scala> rightNone.bisequence res1: Option[Either[String, Int]] = None scala> val leftSome: Either[Option[String], Option[Int]] = Either.left(Some("foo")) scala> leftSome.bisequence res2: Option[Either[String, Int]] = Some(Left(foo)) scala> val leftNone: Either[Option[String], Option[Int]] = Either.left(None) scala> leftNone.bisequence res3: Option[Either[String, Int]] = None
Traverse each side of the structure with the given functions.
Traverse each side of the structure with the given functions.
Example:
scala> import cats.implicits._ scala> def parseInt(s: String): Option[Int] = Either.catchOnly[NumberFormatException](s.toInt).toOption scala> ("1", "2").bitraverse(parseInt, parseInt) res0: Option[(Int, Int)] = Some((1,2)) scala> ("1", "two").bitraverse(parseInt, parseInt) res1: Option[(Int, Int)] = None
If F and G are both cats.Bitraverse then so is their composition F[G[_, _], G[_, _]]
If F and G are both cats.Bitraverse then so is their composition F[G[_, _], G[_, _]]
The composition of two Bifunctors is itself a Bifunctor
The composition of two Bifunctors is itself a Bifunctor
apply a function to the "left" functor
apply a function to the "left" functor
Widens A into a supertype AA.
Widens A into a supertype AA. Example:
scala> import cats.implicits._ scala> sealed trait Foo scala> case object Bar extends Foo scala> val x1: Either[Bar.type, Int] = Either.left(Bar) scala> val x2: Either[Foo, Int] = x1.leftWiden