MarioAriasC/funKTionale

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

y2k opened this issue · 4 comments

y2k commented

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?

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

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) }

'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

This was fixed several weeks ago

fun <P1, R> ((P1) -> R).partially1(p1: P1): () -> R {