Last active
December 10, 2015 02:18
-
-
Save aryairani/4366194 to your computer and use it in GitHub Desktop.
Why is the type inferred for f1 but not for f2?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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