MarioAriasC / funKTionale

Functional constructs for Kotlin
914 stars 71 forks source link

'partially(...)' for multiple arguments functions? #13

Closed y2k closed 7 years ago

y2k commented 8 years ago

Can I transform function like fun myProc(a:Int, b: String, c: Float) to fun myProc(c:Float) in one step?

Right now I use code myProc.partially1(1).partially1("") , but maybe there are best solution?

MarioAriasC commented 8 years ago

You could use the invoke style flavour

myProc(1)("")

Is in the same package

As having a multi parameter version is hard to implement due to mathematical constraints. The library will end being in gigabytes size. Scala has this feature embedded inside the compiler.

Other solution is to create your own extension function for your particular case

y2k commented 8 years ago

Yes I understand. One more question. Why you don't have partially1 for function with one argument? fun <P1, R> Function1<P1, R>.partially1(p1: P1): () -> R = { this(p1) }

MarioAriasC commented 8 years ago

'Cause in that case isn't partial application but parameter binding. Someone suggest that feature on our channel in Kotlin's Slack a few weeks ago

I could consider adding it but with bind name, not partiallyN

MarioAriasC commented 7 years ago

This was fixed several weeks ago https://github.com/MarioAriasC/funKTionale/blob/53b162f8de7a3c2702777b8f82c6bb344087edaa/funktionale-partials/src/main/kotlin/org/funktionale/partials/namespace.kt#L1029