HOI-Comprehensions
view release on metacpan or search on metacpan
Currently, the generators are handled in sequence of the argument list offered by the user.
As a result of such implementation, a list
{ (x, y) | x belongs to { 0, 1 }, y belongs to natural number set }
may be trapped in the inner infinite loop. To avoid such situation, make sure finite generators
are subsequent to all the infinite ones.
FUNCTIONS
comp($@)->(@)
For creating a list comprehension object. The formula for computing the elements of
the list is given as a subroutine, following by the generators, in form of name => arrayref,
name => subroutine or name => comprehension. Comp returns a function which takes all guards
in form of subroutines. Guard parameters can be left empty if there is no guard.
The variable names for naming the ganerators could be used directly in the computation sub and
all guard subs without strict vars enabled. They have local scope as if they were declared with
keyword 'local' in Perl.
A hashref which holds generator variables as its keys and value of those variables as
its values is passed to the formula subroutine. However, it is recommended to use such
variables directly instead of dereference the hashref.
Generators can be arrayrefs or subroutines or list comprehensions. A subroutine generator
should return a pair ( elt, done ), where elt is the next element and done is a flag telling
whether the iteration is over, or return a single element.
It is possible that some generator A is dependent on another generator B. In that case, B
must be subsequent to A. See test cases for details.
The subroutine comp is in EXPORT_OK, but it is not exported by default
lib/HOI/Comprehensions.pm view on Meta::CPAN
Currently, the generators are handled in sequence of the argument list offered by the user.
As a result of such implementation, a list
{ (x, y) | x belongs to { 0, 1 }, y belongs to natural number set }
may be trapped in the inner infinite loop. To avoid such situation, make sure finite generators
are subsequent to all the infinite ones.
=head1 FUNCTIONS
=head2 comp($@)->(@)
For creating a list comprehension object. The formula for computing the elements of
the list is given as a subroutine, following by the generators, in form of name => arrayref,
name => subroutine or name => comprehension. Comp returns a function which takes all guards
in form of subroutines. Guard parameters can be left empty if there is no guard.
The variable names for naming the ganerators could be used directly in the computation sub and
all guard subs without strict vars enabled. They have local scope as if they were declared with
keyword 'local' in Perl.
A hashref which holds generator variables as its keys and value of those variables as
its values is passed to the formula subroutine. However, it is recommended to use such
variables directly instead of dereference the hashref.
Generators can be arrayrefs, subroutines or list comprehensions. A subroutine generator should
return a pair ( elt, done ), where elt is the next element and done is a flag telling whether
the iteration is over, or return a single element.
It is possible that some generator A is dependent on another generator B. In that case, B
must be subsequent to A. See test cases for details.
The subroutine comp is in EXPORT_OK, but it is not exported by default.
( run in 0.275 second using v1.01-cache-2.11-cpan-26ccb49234f )