line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Generator;
|
2
|
1
|
|
|
1
|
|
24479
|
BEGIN {require List::Gen}
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
List::Generator - provides functions for generating lists
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
version 0.974
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
this module is an alias for L. it is the same as L in
|
15
|
|
|
|
|
|
|
every way.
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use List::Generator;
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $range = <1 .. 1_000_000_000 by 3>;
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $squares = gen {$_ ** 2} <1..>;
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $fib = <0, 1, *+* ...>;
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
say "@$fib[0 .. 10]"; # 0 1 1 2 3 5 8 13 21 34 55
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
list(1 .. 5)->map('*2')->say; # 2 4 6 8 10
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
<1..>->zip('.' => )->say(5); # 1a 2b 3c 4d 5e
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
each line below prints C< '1 9 25 49 81' >:
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
functions: (gen {$_**2} filter {$_ % 2} 1, 10)->say;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
list comprehensions: <**2 for 1 .. 10 if odd>->say;
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
dwimmy methods: <1..10>->grep('odd')->map('**2')->say;
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
normal methods: range(1, 10)->grep(sub {$_%2})->map(sub {$_**2})->say;
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 LINKS
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * see L for core documentation.
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item * see L for performance tips.
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item * see L for usage tips.
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item * see L for an experimental implementation of haskell's
|
52
|
|
|
|
|
|
|
lazy list behavior.
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item * see L for the tools used to create L.
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item * see L for some of perl's operators implemented as lazy
|
57
|
|
|
|
|
|
|
haskell like functions.
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * see L for most of perl's builtin functions
|
60
|
|
|
|
|
|
|
implemented as lazy haskell like functions.
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * see L for a source filter that adds perl6's meta
|
63
|
|
|
|
|
|
|
operators to use with generators, rather than the default overloaded operators
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=back
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHOR
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Eric Strom, C<< >>
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
copyright 2009-2011 Eric Strom.
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
this program is free software; you can redistribute it and/or modify it under
|
76
|
|
|
|
|
|
|
the terms of either: the GNU General Public License as published by the Free
|
77
|
|
|
|
|
|
|
Software Foundation; or the Artistic License.
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
see http://dev.perl.org/licenses/ for more information.
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1;
|