Skip to content

Instantly share code, notes, and snippets.

@kareblak
Last active January 3, 2016 11:29
Show Gist options
  • Save kareblak/8456943 to your computer and use it in GitHub Desktop.
Save kareblak/8456943 to your computer and use it in GitHub Desktop.
Where's the structural type?
object FuncConversions {
//Nay
implicit def guavaFunction2function[A, R](fn: (A) => R) = {
new com.google.common.base.Function[A, R]{
def apply(input: A): R = fn(input)
}
}
//Yay
class Func[A, B](fn: (A) => B) extends com.google.common.base.Function[A, B] {
def apply(input: A): B = fn(input)
}
implicit def guavaFunction2function[A, B](fn: (A) => B) = new Func[A, B](fn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment