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.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With