macrame icon indicating copy to clipboard operation
macrame copied to clipboard

Add autoFold function.

Open ClaireNeveu opened this issue 8 years ago • 0 comments

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)
}

ClaireNeveu avatar May 04 '16 19:05 ClaireNeveu