Last active
December 26, 2015 04:29
-
-
Save drostron/7093230 to your computer and use it in GitHub Desktop.
This file contains 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
object TypeClassExample { | |
trait UnicodeOrdered[T] { | |
def ≤(i:T,j:T): Boolean | |
} | |
object UnicodeOrdered { | |
implicit object UnicodeOrderedInt extends UnicodeOrdered[Int] { | |
def ≤(i:Int,j:Int): Boolean = i <= j | |
} | |
implicit object UnicodeOrderedLong extends UnicodeOrdered[Long] { | |
def ≤(i:Long,j:Long): Boolean = i <= j | |
} | |
} | |
object UnicodeOrderedOps { | |
implicit class EnrichedUnicodeOrderedOps[T](content: T)(implicit m:UnicodeOrdered[T]) { | |
def ≤(v:T) = m.≤(content,v) | |
} | |
} | |
} |
This file contains 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
scala> import TypeClassExample._, UnicodeOrderedOps._ | |
import TypeClassExample._ | |
import UnicodeOrderedOps._ | |
scala> 1 ≤ 2 | |
res0: Boolean = true | |
scala> 1L ≤ 2 | |
res1: Boolean = true | |
scala> 1.0 ≤ 2 | |
<console>:14: error: could not find implicit value for parameter m: misc.TypeClassExample.UnicodeOrdered[AnyVal] | |
1.0 ≤ 2 | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment