I created following code snippet:
class PimpToRight[A](f: A => Boolean) {
def <| (a: A) = f(a)
}
implicit def f2pimp[A](f: A => Boolean) = new PimpToRight(f)
class PimpToLeft[A](a: A) {
def <|: (f: A => Boolean) = f(a)
def |> (f: A => Boolean) = f(a)
}
implicit def a2pimp[A](a: A) = new PimpToLeft(a)
There are right- and left-associative methods available.
Following code works:
((_: Int) > 3) <| 7
((_: Int) > 3) <|: 7
7 |> (_ > 3)
But this does not:
(_ > 3) <| 7
(_ > 3) <|: 7
Is it possible to infer type parameters from right to left?
Type inference is the ability to automatically deduce, either partially or fully, the type of an expression at compile time. The compiler is often able to infer the type of a variable or the type signature of a function, without explicit type annotations having been given.
Contextual typing occurs when the type of an expression is implied by its location. For example: window . onmousedown = function ( mouseEvent ) { console .
Type inference enables a compiler to deduce the type of a particular expression automatically when it compiles your code, simply by examining the values you provide. Because of type inference, Swift requires far fewer type declarations than languages such as C or Objective-C.
Type inference is a Java compiler's ability to look at each method invocation and corresponding declaration to determine the type argument (or arguments) that make the invocation applicable.
These two issues are related: SI-4773 and SI-1980. Based on these issues, the answer to your question seems to be no. While not directly related to your question, there is a very nice post by Paul Chiusano on making the most of type inference in Scala, which addresses the current state of type inference in Scala and provides some useful advice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With