The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Perlude - a prelude for perl

VERSION

Version 0.01

SYNOPSIS

Perlude functions are filters and consumers for generators (Closures). It adds keywords stolen from the haskell world and introduce some perl specific ones.

Rules, naming and conventions

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 ...

Notes for haskell users

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 }

EXPORT

FUNCTIONS

take $n, $C

take $n elements from $C

    fold take 10, sub { state $x=0; $x++ }
    #  => 0..9

takeWhile $test, $C

take all the first elements from the closure that matches $test.

    fold takeWhile { $_ < 100 } fibonacci
    # returns every terms of the fibonacci sequence under 100

filter $test, $C

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 $C

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

unfold $array_ref

stream the array elements

    mapR {say if /5/ } unfold [1..5];
    is like
    map {say if /5/} 1..5;

AUTHOR

Marc Chantreux, <khatar at phear.org>

BUGS

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.

SUPPORT

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

    perldoc Perlude

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

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.