1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
NAME
List::Gather::Simple - Simple implementation of gather/take
SYNOPSIS
use List::Gather::Simple;
print gather {
take for gather {
take 'Hello ', 'world!';
};
unshift @gathered, 'Test message: ';
}, "\n";
# -> Test message: Hello world!
DESCRIPTION
List::Gather::Simple is yet another Perl 5 implementation of the
"gather"/"take" construct in Perl 6/Raku. It differs from other
implementations in that it is, as the name suggests, very simple.
"gather" and "take" are implemented as normal subroutines, operating on
a localized variable called @gathered. All three of these are imported
when List::Gather::Simple is "use"d.
The benefit of exporting @gathered as a variable (rather than a
subroutine called "gathered") is that @gathered is very clearly a normal
Perl array, which can be used as an lvalue too, unlike the "gathered"
subroutine of other implementations. That means that the following is
valid:
gather { @gathered = merge(@gathered, @x) while @x }
DIAGNOSTICS
Warning: Useless use of 'gather' in void context
This warning is issued if "use warnings 'void'" is active and
"gather" is called in void context.
Note that the warning will be associated with the line on which
"gather" is called. This can lead to the following unintuitive
behavior: If you return the results of "gather" from a subroutine
and then call that subroutine in void context, the warning will
still be issued, but it will refer to the line of the "gather" call
inside the subroutine.
Exception: Call to 'take' outside of 'gather'
This exception is raised if "take" is called outside of a "gather"
block.
Note that this is a runtime error.
SEE ALSO
All of the following modules have inspired List::Gather::Simple:
* List::Gather
* Perl6::Gather
* Perl6::Take
* Syntax::Keyword::Gather
AUTHOR
John Ankarström, <john+spam@ankarstrom.se> (remove +spam)
COPYRIGHT AND LICENSE
Copyright (C) 2021 by John Ankarström
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.32.1 or, at
your option, any later version of Perl 5 you may have available.
|