Combine an F[A]
and an F[B]
into an F[(A, B)]
that maintains the effects of both fa
and fb
.
Combine an F[A]
and an F[B]
into an F[(A, B)]
that maintains the effects of both fa
and fb
.
Example:
scala> import cats.implicits._ scala> val noneInt: Option[Int] = None scala> val some3: Option[Int] = Some(3) scala> val noneString: Option[String] = None scala> val someFoo: Option[String] = Some("foo") scala> Semigroupal[Option].product(noneInt, noneString) res0: Option[(Int, String)] = None scala> Semigroupal[Option].product(noneInt, someFoo) res1: Option[(Int, String)] = None scala> Semigroupal[Option].product(some3, noneString) res2: Option[(Int, String)] = None scala> Semigroupal[Option].product(some3, someFoo) res3: Option[(Int, String)] = Some((3,foo))
Transform an F[A]
into an F[B]
by providing a transformation from A
to B
and one from B
to A
.
Transform an F[A]
into an F[B]
by providing a transformation from A
to B
and one from B
to A
.
Example:
scala> import cats.implicits._ scala> import scala.concurrent.duration._ scala> val durSemigroup: Semigroup[FiniteDuration] = | Invariant[Semigroup].imap(Semigroup[Long])(Duration.fromNanos)(_.toNanos) scala> durSemigroup.combine(2.seconds, 3.seconds) res1: FiniteDuration = 5 seconds
Lifts natural subtyping contravariance of contravariant Functors.
Lifts natural subtyping contravariance of contravariant Functors. could be implemented as contramap(identity), but the Functor laws say this is equivalent
point
lifts any value into a Monoidal Functor.
point
lifts any value into a Monoidal Functor.
Example:
scala> import cats.implicits._ scala> InvariantMonoidal[Option].point(10) res0: Option[Int] = Some(10)
trivial
produces an instance of F
for any type A
that is trivial with respect to contramap2
along
the diagonal
ContravariantMonoidal functors are functors that supply a unit along the diagonal map for the
contramap2
operation.Must obey the laws defined in cats.laws.ContravariantMonoidalLaws.
Based on ekmett's contravariant library: https://hackage.haskell.org/package/contravariant-1.4/docs/Data-Functor-Contravariant-Divisible.html