On Thursday, 21 January 2016 at 13:15:46 UTC, Rikki Cattermole
wrote:
Ok so input ranges.
An input range is a little bit like an iterator (if you know
what that is).
When an input range has been read fully, it is empty aka no
longer has any values associated with it.
writeln, reads an input range fully (since you can't ask for
what is next without removing the current item) and outputs
each entry.
So yes, writeln will remove all entries from an input range.
Note however it will not do this for arrays since you can read
anywhere within them.
Thanks for your reply.
So writeln consumes the values in an InputRange. That leads me to
believe that if I feed an InputRange to foreach, it will consume
the values, too.
Did I get that right ?
If that's the case, why I can iterate and write the values just
fine using nested foreach loops *and* writeln them afterwards ?
I would expect the foreach loops leaves "step3" in the same state
as writeln does.
So I'm still a little confused as to how foreach goes about it. I
thought foreach would be iterating an InputRange the same way
writeln does.
By attaching ".array" to the result of I was under the impression
the result was actually converted to an array.
That seems not to be the case. What I probably got was something
like an array of arrays of groups - which are apparently
InputRanges ?
So, yes, writeln... InputRange... makes perfect sense except for
the foreach case.
Thanks again for the help :)