Skip to content

Instantly share code, notes, and snippets.

@aryairani
Last active December 10, 2015 02:18
Show Gist options
  • Save aryairani/4366194 to your computer and use it in GitHub Desktop.
Save aryairani/4366194 to your computer and use it in GitHub Desktop.
Why is the type inferred for f1 but not for f2?
implicit class Provided[A](f: A => A) {
def provided(c: A => Boolean): A => A =
a => if (c(a)) f(a) else a
def ->:(c: A => Boolean) = provided(c)
def <--(c: A => Boolean) = provided(c)
}
def add(x: Int) = (_:Int) + x
val f1 = add(3) <-- (_ < 5)
val f2 = (_ < 5) ->: add(3)
// error: missing parameter type for expanded function ((x$1) => x$1.$less(5))
// val f2 = (_ < 5) ->: add(3)
// ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment