NAME
FP::Stream - functions for lazily generated, singly linked (purely functional) lists
SYNOPSIS
use FP::Stream ':all';
stream_length stream_iota (101, 5)
# => 5;
stream_length stream_iota (undef, 5000000)
# => 5000000;
stream_iota->map(sub{ $_[0]*$_[0]})->take(5)->sum
# => 30 (0+1+4+9+16)
use FP::Lazy;
force stream_fold_right sub { my ($n,$rest)=@_; $n + force $rest }, 0, stream_iota undef, 5
# => 10;
# Alternatively, use methods:
stream_iota(101, 5)->length # => 5
# note that length needs to walk the whole stream
# also, there's a {stream_,}fold (without the _right) function/method:
stream_iota(undef, 5)->fold(sub { my ($n,$rest)=@_; $n + $rest }, 0)
# NOTE that the method calls are forcing evaluation of the object
# (the first cell of the input stream), since that's the only way to
# know the type to be dispatched on. This is unlike the non-generic
# functions, some of which (like cons) don't force evaluation of
# their arguments.
DESCRIPTION
Create and dissect sequences using pure functions. Lazily.