Method reference with argument

I am looking for a way to map the selected String tab to an array. I am currently doing this with a lambda expression:

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

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

+7
java java-8 currying
source share
1 answer

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 can:

 stream.map(curry(String::split, "\t")); 
+7
source share

All Articles