API question for point lambdafication

Ben Evans benjamin.john.evans at gmail.com
Tue Feb 19 12:45:04 PST 2013


I've got my regex point lambdafication patch going against the current
state of lambda, but now I have an API question I'd like some feedback

(Btw, if this is more appropriate for core-libs just let me know, and
I'll take my carcass over there & bug those guys instead.)

I currently have this new method on java.util.regex.Pattern:

public Stream<CharSequence> splitAsStream(final CharSequence input);

This provides a stream of values from the input CharSequence, split
around occurrences of this pattern.

However, as the return type of splitAsStream() is
Stream<CharSequence>, then we need to map stream values back to String
to be most useful, like this:

	List<String> out = p.splitAsStream(s)
                            .map(cs -> cs.toString())

So, my question is this - should I continue to use the above
signature, or should it be:

public Stream<String> splitAsStream(final CharSequence input);

This avoids the need for the intermediate map(), which seems like a
bit of a wart to me.

Pattern has a vanilla split() method, which returns String[] - so for
those 2 reasons I'm minded towards the second form.

Anyone else have any thoughts about this?


More information about the lambda-dev mailing list