Is there a way to express the inverse of any function in Scala?
For example if I have a function f like this:
f
(x: Int) => x + 1
From pragmatistic view, unapply method could be used to represent inverse functions:
unapply
object f { def apply(x: Int) = x + 1 def unapply(x: Int) = Some(x - 1); } val x = 1 val f(y) = f(x) assert(x == y)