Two questions about forEach
greggwon at gmail.com
Thu Aug 9 07:55:47 PDT 2012
Eager is fine, the return value is the question. Adding an additional API interface such as tap might be smarter from the perspective of providing the right view of the behavior expected.
Lazy and eager are fine terms. But we should also consider some naming conventions which mean Lazy and Eager so that developer can unequivocally make a good decision about what they need.
As an example, the prefix 'as' could imply eager while 'when' or 'into' might mean lazy.
I've been meaning to bring this up, because I think it will make lambda usage much more tractable if developers can easily manage their thoughts around how the API will work.
Sent from my iPhone
On Aug 9, 2012, at 7:46 AM, Rémi Forax <forax at univ-mlv.fr> wrote:
> On 08/09/2012 02:30 PM, Gregg Wonderly wrote:
>> On 8/9/2012 2:22 AM, Mike Duigou wrote:
>>> Does every item get refreshed in order to complete findFirst? Do you really
>>> want findFirst to inspect every element? The semantics and efficiency are
>> Yes, but I still really feel that "guessing" and "optimizing" how efficiency
>> will be achieved, before we've had this in the wild, is completely premature.
>> I know that this feels, right now, like a lazy programming style, which then
>> becomes an inefficient run time execution. But, do we really want to set, in
>> stone, that foreach, can't return the stream?
>> Gregg Wonderly
> It's part of the design to segregate lazy and eager operations and
> these choices are (or will be) reflected in the doc of the API.
> So the question is more do we need a lazy dual of forEach (tap as
> suggested by Craig).
> Nonetheless, forEach is and will stay eager.
More information about the lambda-dev