-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
["Request"] Partial function application "invoke" no longer available #2693
Comments
Hey @dmstocking, This was an intentional removal because it blows up the binary quite a lot, and it's typically not very useful in Kotlin. Typically it's more straightforward to just create an anonymous lambda instead, and capture the values inside. fun theFn(string1: String, string2: String, string3 : String) = string1 + string2 + string3
val partiallyApplied = { str: String -> theFn("Hello", "World", str) }
listOf("!", "?", ".").map(partiallyApplied) or simply listOf("!", "?", ".").map { theFn("Hello", "World", it) } Not sure if your use case is different from this, but this typically results in more idiomatic Kotlin. |
We were trying to build two variants of an object for testing. One needed a version that had a real dependency that used Netty and another was using an EmbeddedChannel, so that we didn't need to actually connect to something. Anyway the only difference between the two classes was a few arguments. So, I wanted to remove the duplicated code, and I actually used a lambda at one point. The problem though is it is a fairly big lambda. Anyway, let me show you how the changes went down. Note that I changed some of the names so that they are shorter. Most of the real code has more descriptive names that force putting arguments on separate lines.
The last 4 arguments are all the same. So, why not just make a function that creates those and you just pass the lambda on what you want to create? That is exactly what I did, but it turns into.
With Partial Application, I could do.
Which I felt looked really nice and was easier to maintain. |
@dmstocking are you still interested in pursuing this? Maybe we can find a nicer design which doesn't require tons of utility functions in the library. |
I would love some way to make this easier. I don't have any suggestions though. I haven't thought about this in a while. Was there any thoughts on how to do that? (I am sort of assuming you want to clear out old tickets if nothing is going to be done with them) |
I think the best way forward to support such functionality, this includes all functionality such as Such that you can add these functions in an |
What version are you currently using?
Arrow Core 1.0.1
What would you like to see?
It looks like when the new git repository was made. partials.kt's invoke function was not brought over. I can't find an explanation as to why. So, I am not sure if this was an oversight or an intention choice. I am trying to do the same thing that #814 was trying to do. The proposed solution is no longer available though as of 1cd9a90#diff-c32792a648907577ba1b8c6f75dd29ceef90404be1348a501f8f136ef9e8681b. Was this on purpose? How do you partially apply multiple arguments besides just doing
partial1(..)
multiple times?The text was updated successfully, but these errors were encountered: