hg: lambda/lambda/jdk: Add BufferedReader.lines

Brian Goetz brian.goetz at oracle.com
Sun Nov 11 15:30:31 PST 2012


Yeah, Henry already pointed that out to me :(

But yes, this illustrates our strategy for library lambdafication, which 
might better be called streamification.  We're adding stream-bearing 
methods in lots of places -- String.chars(), Reader.lines(), etc. 
Originally we had thought to have methods like eachLine(Block), but 
providing a Stream view is far more flexible -- you can bring the full 
power of the Stream API to bear.

For methods that already return an aggregate (e.g., Class.getMethods()), 
no additional work is needed to access streams, since there will be easy 
ways to convert an array, collection, Iterator, or Enumeration to a 
Stream.

Happy to get additional suggestions about where else in the JDK we can 
replace existing one-at-a-time constructs with Streams, if you've got.

On 11/11/2012 6:24 PM, Arne Siegel wrote:
> Hi Brian,
>
> nice utility function, though I don't think you got the if statement in next() right.
>
> @Override
> public String next() {
>      if (nextLine == null || hasNext()) {
>          try {
>              return nextLine;
> ...
>
> Better keep it simple:
> ...
>      if (hasNext()) {
> ...
>
> Arne Siegel
>
>
> On 11 Nov 2012 at 22:50, brian.goetz at oracle.com wrote:
>
>> Changeset: 94d64473e8e6
>> Author:    briangoetz
>> Date:      2012-11-11 17:44 -0500
>> URL:       http://hg.openjdk.java.net/lambda/lambda/jdk/rev/94d64473e8e6
>>
>> Add BufferedReader.lines
>>
>> ! src/share/classes/java/io/BufferedReader.java
>> ! src/share/classes/java/io/Reader.java
>> + src/share/classes/java/io/UncheckedIOException.java
>>
>>
>
>


More information about the lambda-dev mailing list