API question for point lambdafication
zhong.j.yu at gmail.com
Tue Feb 19 21:49:14 UTC 2013
On Tue, Feb 19, 2013 at 2:45 PM, Ben Evans
<benjamin.john.evans at gmail.com> wrote:
> 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);
`input.subSequence()` can be expensive anyway; in String,
StringBuilder and StringBuffer, the method will copy the chars in
range. Therefore you may as well do the copy yourself to make Strings.
Currently String does not have a constructor like
public String(CharSequence source, int offset, int count)
maybe it should be added?
> 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 core-libs-dev