Iterators: Difference between revisions
m
→{{header|Raku}}: abstract away some intermediate variables to not clutter up the example
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: abstract away some intermediate variables to not clutter up the example) |
||
Line 138:
Rakus iterators are one direction only (not reversible), and once the iteration has been reified, it is discarded unless explicitly cached. This allows effortless iteration through multi-gigabyte sized data objects and streams without filling up main memory.
The following example iterates though a hash of Positional Iterable objects and demonstrates object slice operations on each; then has a semi contrived example of where directly using iterators may be actually useful in Raku; collating unique ascending values from several infinite sequence generators.
<lang perl6>my %positional-iterable-types =
Line 159:
say "\nWhere iterators really shine; when you are trying to collate the values from several infinite generators.";
my @
my @v = @i[0].pull-one, @i[1].pull-one, @i[2].pull-one;
|