I was wondering if there is any way to pull that in Java. I think it is not possible without native support for closures.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This is a library for currying and partial application in Java :
https://github.com/Ahmed-Adel-Ismail/J-Curry
It also supports destructuring Tuples and Map.Entry into method parameters, like for example passing a Map.Entry to a method that takes 2 parameters, so the Entry.getKey() will go to the first parameter, and the Entry.getValue() will go for the second parameter
More details in the README file
Currying and partial application is absolutely possible in Java, but the amount of code required will probably turn you off.
Some code to demonstrate currying and partial application in Java:
FWIW here is the Haskell equivalent of above Java code:
Currying requires to return a function. This is not possible with java (no function pointers) but we can define and return a type that contains a function method:
Now let's curry a simple division. We need a Divider:
and a DivideFunction:
Now we can do a curried division: