Last active
August 29, 2015 14:02
-
-
Save Oregu/76272fd4d7ce6584128e to your computer and use it in GitHub Desktop.
Underscore java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////// | |
// | |
// Moved to repository: | |
// https://github.com/Oregu/_.java | |
// | |
///////////////////////////////////////////////////// | |
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
public interface _ { | |
static <T,U,R> Function<T, Function<U, R>> curry(BiFunction<T, U, R> bi) { | |
return t -> u -> bi.apply(t ,u); | |
} | |
static IntFunction<IntUnaryOperator> curry(IntBinaryOperator bi) { | |
return l -> r -> bi.applyAsInt(l ,r); | |
} | |
static <T,U,R> Function<U, R> partial(BiFunction<T, U, R> bi, T t) { | |
return u -> bi.apply(t ,u); | |
} | |
static <CT extends List<T>, T, R> List<R> map(Function<T, R> f, CT coll) { | |
return coll.stream().map(f).collect(toList()); | |
} | |
} |
currySum = _.curry((int a, int b) -> a+b);
sumWith7 = currySum.apply(7);
import static java.util.stream.Collectors.toList; ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_.map(Field::getName, fields)