1Iterator(3) User Contributed Perl Documentation Iterator(3)
2
3
4
6 Class::Iterator - Iterator class
7
9 use Class::Iterator;
10 my $it = Class::Iterator->new(\&closure_generator);
11
12 while (my $v = $it->next) { print "value : $v\n" }
13
14 # use map like
15 my $it2 = imap { ...some code with $_...} $it
16 while (my $v = $it->next) { print "value : $v\n" }
17
18 # use grep like
19 my $it3 = igrep { ...some code with $_...} $it
20 while (my $v = $it->next) { print "value : $v\n" }
21
23 Class::Iterator is a generic iterator object class. It use a closure an
24 wrap into an object interface.
25
26 new(\&closure_generator)
27 This is the constructor. The argument is a sub which look like
28 sub closure_generator {
29 my $private_data;
30 return sub {
31 # do something with $private_data
32 # and return it
33 return $private_data
34 } }
35
36 next
37 calling this method make one iteration.
38
39 $o = imap { ... } $it
40 This a creator. It create a new iterator from an existant iterator
41 in the manner of map.
42
43 $o = igrep { ... } $it
44 This a creator. It create a new iterator from an existant iterator
45 in the manner of grep.
46
48 Marc Jason Dominius's YAPC::EU 2003 classes. Ken Olstad
49
51 Robert Silve <robert@silve.net>
52
53
54
55perl v5.36.0 2023-01-20 Iterator(3)