Scalar::Induce - Unfolding scalars


Scalar-Induce documentation Contained in the Scalar-Induce distribution.

Index


Code Index:

NAME

Top

Scalar::Induce - Unfolding scalars

VERSION

Top

Version 0.02

SYNOPSIS

Top

	my @reversed = induce { @$_ ? pop @$_ : void undef $_ } [ 1 .. 10 ];

	my @chunks = induce { (length) ? substr $_, 0, 3, '' : void undef $_ } "foobarbaz";

FUNCTIONS

Top

All functions are exported by default.

induce

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.

void

This is a utility function that always returns an empty list (or undefined in scalar context). This makes a lot of inductions simpler.

AUTHORS

Top

Leon Timmermans, <leont at cpan.org>, Aristotle Pagaltzis <pagaltzis at gmx.de>

BUGS

Top

Please report any bugs or feature requests to bug-scalar-induce at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Scalar-Induce. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Scalar::Induce

You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Scalar-Induce

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Scalar-Induce

* CPAN Ratings

http://cpanratings.perl.org/d/Scalar-Induce

* Search CPAN

http://search.cpan.org/dist/Scalar-Induce

ACKNOWLEDGEMENTS

Top

Aristotle Pagaltzis came up with this idea (http://use.perl.org/~Aristotle/journal/37831). Leon Timmermans merely re-implemented it in XS and uploaded it to CPAN.

COPYRIGHT & LICENSE

Top


Scalar-Induce documentation Contained in the Scalar-Induce distribution.

package Scalar::Induce;

use 5.006;
use strict;
use warnings;

use base qw/Exporter DynaLoader/;
our $VERSION = '0.02';
our @EXPORT  = qw/induce void/;

use Scalar::Induce::ConfigData;

if (Scalar::Induce::ConfigData->config('C_support') and not our $pure_perl) {
	bootstrap Scalar::Induce $VERSION;
}
else {
	eval <<'END';
	sub induce (&$) {
		my ( $c, $v ) = @_;
		my @r;
		for ( $v ) { push @r, $c->() while defined }
		@r;
	}
    sub void { return; }
END
}

1;

__END__