Last active
May 3, 2019 09:54
-
-
Save slouc/bf405381197c7fcc6236091f91459bd2 to your computer and use it in GitHub Desktop.
Contravariant functor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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