Skip to content

Instantly share code, notes, and snippets.

@TomLous
Created April 25, 2017 13:48
Show Gist options
  • Select an option

  • Save TomLous/d0f52c6df76cad50aa74bb56e21dac2a to your computer and use it in GitHub Desktop.

Select an option

Save TomLous/d0f52c6df76cad50aa74bb56e21dac2a to your computer and use it in GitHub Desktop.
Example of curried class constructors
trait Parser{
def parse(i: Int):String
}
object ParserA extends Parser{
override def parse(i: Int): String = s"A: $i"
}
object ParserB extends Parser{
override def parse(i: Int): String = s"B: $i"
}
case class CurriedClass(parser: Parser)(y: Int) {
def show = parser.parse(y)
}
val extendedClassA = CurriedClass(ParserA) _
val extendedClassB = CurriedClass(ParserB) _
val n = extendedClassA(3)
val m = extendedClassA(5)
val o = extendedClassB(2)
n.show
m.show
o.show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment