Skip to content

Instantly share code, notes, and snippets.

@pfcoperez
Last active January 27, 2017 13:14
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 pfcoperez/ab002db9f9dcd9f428f19f92f1da978e to your computer and use it in GitHub Desktop.
Save pfcoperez/ab002db9f9dcd9f428f19f92f1da978e to your computer and use it in GitHub Desktop.
abstract class FuncStackable {
def f(x: Int): Int
}
class Fidentity extends FuncStackable {
override def f(x: Int): Int = x
}
trait NInput extends FuncStackable {
val n: Int
abstract override def f(x: Int): Int = super.f(x*n)
}
val doublef = new Fidentity with NInput { val n: Int = 10 }
doublef.f(1)
/////////////////////////////////////////
abstract class IntCol {
def add(x: Int): Unit
def elements: Seq[Int]
}
class ListWrapper extends IntCol {
private var l: List[Int] = Nil
override def add(x: Int): Unit = l = x :: l
override def elements: Seq[Int] = l
}
trait Duplicate extends IntCol {
abstract override def add(x: Int): Unit = {
super.add(x)
super.add(x)
}
}
val duplicator = new ListWrapper with Duplicate
duplicator.add(1)
duplicator.elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment