I'm playing with functions. Here, the restriction...
# arrow
j
I'm playing with functions. Here, the restriction I've set for myself is that f2 depends on f1 and f1 depends on E, but E must be supplied late, after the program has already been constructed. All that's fine, as far as it goes. I'm particularly interested in the function
f3
. It seems like there might be a named pattern for what it's doing. It kind of behaves like
partially
, except it defers the partial application till later. Then it partially applies to f2 the result of executing the deferred function (when that happens). If such a pattern exists, what's its name? Do helper functions already exist in Arrow to do this for me? Basically, is there a better way? Thanks much!
j
@raulraja Kind of. But with the
curry
function in
core
one has to respect the order of the parameters of the function being curried.
I also got a similar result this way:
Copy code
val r1 = Reader { e: E -> Id(f1(p3 = e)) }
val r2 = r1.map { f -> Reader { a: A -> Id(f(p1 = a)) } }
val d = r2.runId(E()).runId(A())(F())
I don't know what I'm doing. 🤣 I'm just kinda pounding at the keyboard and seeing what happens.
r
This is very similar to a technique in scala called PartiallyApplied which is used to only have to provide one type arg instead of two in functions that take two. You create a class that partially applies the first arg then the second
j
@raulraja Yeah, that sounds right.
r
Reader and Id are still there for the novelty but they are kind of pointless in Kotlin since the same can be expressed in direct style with the same semantics:
Copy code
fun E.r1() = f1(...)
fun A.r2() = r1(...)
fun d() = E().r2(...
j
That's really interesting! I'm going to try translating what I have to ^.