Created
August 29, 2016 16:01
-
-
Save YuvalItzchakov/88d5a869805bec149ab828f7ca71c400 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 Yuval extends App { | |
class Animal { | |
this: Reflect => | |
} | |
implicit def reflectOrdering: Ordering[Animal with Reflect] = Ordering.by(e => e.canReflect) | |
object Animal { | |
def isGreaterAnimal(first: Animal with Reflect, second: Animal with Reflect)(implicit ev: Ordering[Animal with Reflect]) = ev.gt(first, second) | |
} | |
trait Reflect{ | |
val canReflect: Boolean | |
} | |
trait Reflective extends Reflect{ | |
val canReflect = true | |
} | |
trait Automaton extends Reflect{ | |
val canReflect = false | |
} | |
val reflective = new Animal with Reflective | |
val robot = new Animal with Automaton | |
println(Animal.isGreaterAnimal(reflective, robot)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whats the difference between:
class Animal {
this: Reflect => // I have never seen this syntax? what does it do?
}
and
class Animal with Reflect