The type of this function is T -> (T -> U) -> U
. I believe that in Haskell, it would be something like ($ . flip)
.
Or, from an object-oriented perspective (which is the way I've been looking at it):
type T {
U myFunction(f: T -> U) {
return f(this);
}
}
I've been calling it "into" in my notes, and using a single arrow (->
) as an operator. It's analogous to the map
function, but for a scalar:
a.into f = f(a)
[a, b, c].map f = [f(a), f(b), f(c)]
Examples of practical applications:
42 -> Math.sqrt
foo.bar.into(doSomething).baz.into(doSomethingElse).xyzzy
(rather than doSomethingElse(doSomething(foo.bar).baz).xyzzy)