Range of n lines from stdin
Ivan Kazmenko
gassa at mail.ru
Fri Dec 27 06:26:59 PST 2013
Quick question.
(1) I can do
n.iota.map!(_ => readln)
to get the next n lines from stdin.
(2) However, when I do
readln.repeat(n)
it looks clearer but works differently: preserves front and reads
only one line.
(3) In the particular case of readln, we can substitute it with
stdin.byLine.take(n)
but the question remains for other impure functions.
So, what I ask for is some non-caching repeat for functions with
side effects. More idiomatic than (1). Is there something like
that in Phobos? Is it an OK style to have an impure function in
an UFCS chain?
If repeat could know whether its first argument is pure, it could
then enable or disable front caching depending on purity... no
way currently?
Ivan Kazmenko.
More information about the Digitalmars-d-learn
mailing list