macrame
macrame copied to clipboard
Add autoFold function.
autoFold
function that matches the correct functions to the correct cases. Given:
sealed trait Foo
case class Bar(i : Int) extends Foo
case class Baz(s : String) extends Foo
val foo : Foo = Bar(5)
def barF(b : Bar) : String = b.i
def bazF(b : Baz) : String = b.s
both
foo.autoFold(barF _, bazF _)
and
foo.autoFold(bazF _, barF _)
compile to
foo match {
case b @ Bar(_) => barF(b)
case b @ Baz(_) => bazF(b)
}