Perlude - a prelude for perl
Version 0.01
Perlude functions are filters and consumers for generators (Closures). It adds keywords stolen from the haskell world and introduce some perl specific ones.
A generator is a closure
* a scalar as a next element
* undef when exhausted
The list of every potential elements of a generator is called "the stream".
sub that takes and returns a closures is a filter, its name is postfixed with a C (mapC, ...).
sub that takes a closure and consume (read) it is a Reader, its name is prefixed with a R (mapR,reduceR,sumR,productR, ...)
keywords stolen from haskell are exceptions to the naming convention (filter,fold,unfold,...)
from haskell: take, takeWhile, filter, fold, (unfold?) concat ...
As perl doesn't have monads, M and M_ functions are replaced by C (for Closure) and R (for Reader). so
mapM_ print => mapR {say} mapM print => mapC {say} map (* 2) => mapC { $_ * 2 }
take $n elements from $C
fold take 10, sub { state $x=0; $x++ } # => 0..9
take all the first elements from the closure that matches $test.
fold takeWhile { $_ < 100 } fibonacci # returns every terms of the fibonacci sequence under 100
remove any elements that matches $test from the steam (as grep does with arrays)
filter { /3/ } fibonacci
removes every terms of fibonacci sequence that contains the digit 3
fold every terms of the steam into an array
my @c4 = fold take 50 filter {/4/} nat;
@c4 is the array of the first 50 naturals that contains the 4 digit
stream the array elements
mapR {say if /5/ } unfold [1..5]; is like map {say if /5/} 1..5;
Marc Chantreux, <khatar at phear.org>
<khatar at phear.org>
Please report any bugs or feature requests to bug-lazyness at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lazyness. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-lazyness at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Perlude
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lazyness
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Lazyness
CPAN Ratings
http://cpanratings.perl.org/d/Lazyness
Search CPAN
http://search.cpan.org/dist/Lazyness
Copyright 2010 Marc Chantreux, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Perlude, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perlude
CPAN shell
perl -MCPAN -e shell install Perlude
For more information on module installation, please visit the detailed CPAN module installation guide.