Skip to content

Instantly share code, notes, and snippets.

@YuvalItzchakov
Created August 29, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuvalItzchakov/88d5a869805bec149ab828f7ca71c400 to your computer and use it in GitHub Desktop.
Save YuvalItzchakov/88d5a869805bec149ab828f7ca71c400 to your computer and use it in GitHub Desktop.
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))
}
@samarism
Copy link

samarism commented Aug 30, 2016

Whats the difference between:
class Animal {
this: Reflect => // I have never seen this syntax? what does it do?
}
and
class Animal with Reflect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment