Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method reference with argument

I'm looking for a way to map a tab separated String to an array. Currently, I'm doing it with a lambda expression:

stream.map(line -> line.split("\t"));

Is there a way to do it with a method reference? I know that stream.map(String::split("\t")) does not work, but am wondering if there is an alternative.

like image 721
mossaab Avatar asked Nov 14 '14 00:11

mossaab


1 Answers

You can do something like this:

static<T,U,R> Function<T,R> curry(BiFunction<? super T, ? super U, ? extends R> f, U u) {
    return t -> f.apply(t, u);
}

and then you'll be able to do:

stream.map(curry(String::split, "\t"));
like image 80
Misha Avatar answered Oct 21 '22 14:10

Misha