Scalar::Induce - Unfolding scalars
version 0.05
my @reversed = induce { @$_ ? pop @$_ : void undef $_ } [ 1 .. 10 ]; my @chunks = induce { (length) ? substr $_, 0, 3, '' : void undef $_ } "foobarbaz";
All functions are exported by default.
This function takes a block and a scalar as arguments and then repeatedly applies the block to the value, accumulating the return values to eventually return them as a list. It does the opposite of reduce, hence its name. It's called unfold in some other languages.
This is a utility function that always returns an empty list (or undefined in scalar context). This makes a lot of inductions simpler.
Aristotle Pagaltzis came up with this idea (http://use.perl.org/~Aristotle/journal/37831). Leon Timmermans re-implemented it in XS and uploaded it to CPAN.
Leon Timmermans <leont@cpan.org>
This software is copyright (c) 2009 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Scalar::Induce, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scalar::Induce
CPAN shell
perl -MCPAN -e shell install Scalar::Induce
For more information on module installation, please visit the detailed CPAN module installation guide.