Skip to content

Instantly share code, notes, and snippets.

@Oregu
Last active August 29, 2015 14:02
Show Gist options
  • Save Oregu/76272fd4d7ce6584128e to your computer and use it in GitHub Desktop.
Save Oregu/76272fd4d7ce6584128e to your computer and use it in GitHub Desktop.
Underscore java
/////////////////////////////////////////////////////
//
// 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());
}
}
@kagel
Copy link

kagel commented Sep 3, 2014

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