[Issue 9550] Repeat!fun(size_t n)
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Jun 25 10:00:15 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=9550
Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |dlang-bugzilla at thecybershad
| |ow.net
Resolution|--- |WONTFIX
--- Comment #4 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
(In reply to daniel from comment #0)
> The use case is where you want to repeat an (impure) function n times lazily.
This doesn't make sense to me. Laziness and impurity do not mix.
> iota(100).map!(x => uniform(0, 76));
This code is conceptually wrong. By itself, this code does nothing. Advancing
the range will do nothing. Advancing the range while evaluating .front will do
something; but so will accessing .front in a loop without advancing the range.
The resulting range object is broken by design in several aspects.
It seems to me that you are trying to shoehorn an operation into a design which
was not really meant for it. In the case of random numbers, the proper solution
would be a PRNG range, which has correctly-implemented .front (which always
returns the same value while not advancing), .popFront (which advances the
PRNG), and .save (which makes a copy of the PRNG's state).
I'll close this as the last activity on this bug was over 4 years ago. If you
think you have a valid use case, feel free to reopen, though I would suggest
creating a forum thread about this first instead.
--
More information about the Digitalmars-d-bugs
mailing list