-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate(foo) | take(n) calls foo n+1 times #819
Comments
The root cause of these |
And we should try to be consistent with other views that do similar things, like |
I also hope that
P.S.
|
I noticed that
generate_n(foo, n)
callsfoo
n
times whilegenerate(foo) | take(n)
calls itn+1
times. Is this by design? If so, what is the rationale?In some situations I would like to guarantee that
foo
is called exactlyn
times, but it seems that I can't always usegenerate_n
. For example, say that I want to do something like this:for_each(generate(foo), [](auto x) { return yield_if(bar(x), x); }) | take(n);
In this case,
foo
might be called more thann
times depending on how oftenbar(x)
returnsfalse
, but I would like to ensure that it is called exactly as many times as it takes to generaten
elements and no more. I don't see how I could do it withgenerate_n
. I guess I would need something likefor_each_n
, which (as far as I can see) only exists as an algorithm and not as a view.The text was updated successfully, but these errors were encountered: