Skip to content

Instantly share code, notes, and snippets.

@ostretsov
Created January 14, 2015 05:44
Show Gist options
  • Save ostretsov/b81b9a7dd72e87af54f2 to your computer and use it in GitHub Desktop.
Save ostretsov/b81b9a7dd72e87af54f2 to your computer and use it in GitHub Desktop.
class BaseIntQueue {
private val buffer = new ArrayBuffer[Int]
def put(x: Int) = buffer += x
def get() = buffer.remove(0)
}
trait Double extends BaseIntQueue {
override def put(x: Int) = super.put(x * 2)
}
trait Inc extends BaseIntQueue {
override def put(x: Int) = super.put(x + 1)
}
val q = new BaseIntQueue with Double with Inc
q.put(0)
q.put(10)
println(q.get()) // outputs 2
println(q.get()) // and 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment