Skip to content

Instantly share code, notes, and snippets.

@slouc
Last active May 3, 2019 09:54
Show Gist options
  • Save slouc/bf405381197c7fcc6236091f91459bd2 to your computer and use it in GitHub Desktop.
Save slouc/bf405381197c7fcc6236091f91459bd2 to your computer and use it in GitHub Desktop.
Contravariant functor
case class Money(amount: Int)
// contramap: B => A => F[A] => F[B]
val contramapFn: Money => Int = (money) => money.amount
implicit val moneyOrd: Ordering[Money] = Ordering.by(contramapFn)
import scala.math.Ordered._
println(Money(13) < Money(20)) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment