-
-
Save dflemstr/607602 to your computer and use it in GitHub Desktop.
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
//This doesn't actually work, since function application has the highest precedence in Scala. | |
def repeat(self: String, times: Int) = self * times | |
val x = "ABC" | |
x~repeat(5) |
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
object Extension { | |
implicit def from[A](a: A): Extension[A] = Extension(a) | |
} | |
case class Extension[A](a: A) { | |
def ~[R](f: A => R): R = f(a) | |
def ~[R, B](f: (A, B) => R): B => R = f(a, _) | |
def ~[R, B, C](f: (A, B, C) => R): (B, C) => R = f(a, _, _) | |
def ~[R, B, C, D](f: (A, B, C, D) => R): (B, C, D) => R = f(a, _, _, _) | |
//...etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment