Re: Stream.fromForEach(Consumer>)

2022-05-25 Thread Peter Levart
er instance `parser` to a Stream of tokens, one would have to do something like this: var parser = new Parser("1 2 3 4"); var stream = Stream.fromForEach(consumer -> parser.parse(consumer::accept)); ...and then the type of stream would be inferred as Stream, not Stream as one would like.

Re: Stream.fromForEach(Consumer>)

2022-05-23 Thread Steven Schlansker
> On May 23, 2022, at 5:53 AM, Brian Goetz wrote: > > This is a nice use of `mapMulti` to create a stream whose contents are > dynamically generated. It is one step short of generators (which we hope > Loom will eventually give us), in that it is restricted to a generator method > that

Re: Stream.fromForEach(Consumer>)

2022-05-23 Thread Brian Goetz
This is a nice use of `mapMulti` to create a stream whose contents are dynamically generated.  It is one step short of generators (which we hope Loom will eventually give us), in that it is restricted to a generator method that generates all of the elements in one invocation.  This is still

Re: Stream.fromForEach(Consumer>)

2022-05-23 Thread forax
- Original Message - > From: "Tagir Valeev" > To: "Remi Forax" > Cc: "core-libs-dev" > Sent: Monday, May 23, 2022 8:01:44 AM > Subject: Re: Stream.fromForEach(Consumer>) > Hello! > > There's a Stream.builder for this purpose:

Re: Stream.fromForEach(Consumer>)

2022-05-23 Thread Tagir Valeev
Hello! There's a Stream.builder for this purpose: var builder = Stream.builder(); new Parser("1 2 3").parse(builder); builder.build().forEach(System.out::println); A little bit more verbose than your suggestion but this way it's more clear that the whole stream content will be buffered. With

Stream.fromForEach(Consumer>)

2022-05-21 Thread Remi Forax
Hi all, a stream is kind of push iterator so it can be created from any object that has a method like forEach(Consumer), but sadly there is no static method to create a Stream from a Consumer of Consumer so people usually miss that creating a Stream from events pushed to a consumer is easy. By