Skip to content

Instantly share code, notes, and snippets.

@hamnis
Last active December 17, 2015 17:09
Show Gist options
  • Save hamnis/5643733 to your computer and use it in GitHub Desktop.
Save hamnis/5643733 to your computer and use it in GitHub Desktop.
class CalculateAndWrap[A, B](f: (A) => B) {
def unapply(input: A): Option[(A,B)] = Some(input -> f(input))
}
val StringAndLength = new CalculateAndWrap((s: String) => s.length)
"foo" match {
case StringAndLength((f,l)) => println(f + " length " + l)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment