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 doc example for imap #2071

Merged
merged 1 commit into from
Dec 6, 2017
Merged
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
15 changes: 15 additions & 0 deletions core/src/main/scala/cats/Invariant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import simulacrum.typeclass
* Must obey the laws defined in cats.laws.InvariantLaws.
*/
@typeclass trait Invariant[F[_]] { self =>

/**
* 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
* }}}
*/
def imap[A, B](fa: F[A])(f: A => B)(g: B => A): F[B]

def compose[G[_]: Invariant]: Invariant[λ[α => F[G[α]]]] =
Expand Down