Closed DillonJettCallis closed 9 years ago
I've got a couple of places where this would fit, so +1.
Sounds reasonable!
Hi!
I'm about to steal that idea for Javaslang, naming it 'partial function application':
// pseudo / no valid code
Function1<T2, R> Function2<T1, T2, R>.apply(T1 t1) = (T2 t2) -> apply(t1, t2);
@danieldietrich Stealing the idea and a couple of users at the same time? Sneaky! ;)
Whooops...
A blog post would steal the rest of the users ;-)
Update: jOOL's Java Stream integration is outstanding. I do not have that in my project.
Don't worry. I'd still love to publish that blog post. jOOL is not a full-fledged functional API (we don't have time for that). We just fill the gaps where very obvious things are missing from the JDK.
You will get it! I'm currently collecting ideas...
@danieldietrich You know, you don't actually have to steal my idea. I can fork javaslang and write it up there too.
@LordBlackhole That would be great but it is already finished. I mentioned you here.
I merge the pull request in a few seconds.
And btw - by hand this would be no fun. There are Function0 to Function26 and Function_i has i - 1 methods for i > 0.
@LordBlackhole : I've added also currying using argument tuples to make the API more complete
-Enhancment
Something I've been finding myself doing quite a bit recently is writing extra lambdas for currying my functions. Turning Functions into Suppliers and BiFunctions into Functions by partially applying the first argument. I was writing some static helper methods for simplifying this when I realized that it would be a lot easier and make more sense to just have those methods on the Function interfaces themselves.
So for example, Function2 would have ....
While not technically the proper definition of Currying, which would require having only one method returning
Function<T1, Function<T2, R>>
, I feel like this would produce code that would be easier to read and more familiar to a Java developer. For example if you had a Function4 and wanted to apply the first three arguments, it'd be a simple matter offunc.curry(var1, var2, var3)
instead offunc.curry().apply(var1).apply(var2).apply(var3)
I'm really liking this library and I would be happy to write up the boiler-plate for this and make a pull request. I just wanted to know if there would be any interest in it.