Usage of Stream.forEachUntilCancelled
forax at univ-mlv.fr
Sun Mar 24 07:14:26 PDT 2013
On 03/24/2013 02:43 PM, Brian Goetz wrote:
> You're thinking sequentially. How would "when does the iteration need
> to stop" work in parallel?
> Short answer: forEachUntilCancelled is not what you think it is. There
> is not a stream primitive for what you want at this time.
otherwise if you want to stop on a given value or property of a value
you can use filter + findFirst,
stream.filter(element.theshold > 1.0).findFirst()
> On 3/24/2013 9:29 AM, Mrityunjay Sharma wrote:
>> Hi All,
>> I was trying to use Stream.forEachUntilCancelled which takes a Consumer and
>> a BooleanSupplier as input parameter, as at any point of time this method
>> can cancel the iteration and return the control. I thought this would work
>> more like while-do statement, so that i can pass the
>> condition(BooleanSupplier) where the iteration needs to stop.
>> But as BooleanSupplier.getAsBoolean does not take any input parameter, then
>> how can we pass a condition where the iteration needs to stop. Is my
>> understanding correct or i am interpreting the method implementation
>> *PS: An implementation Example will be highly appreciated.*
>> Thanks & Regards,
More information about the lambda-dev