The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


FP::Abstract::Sequence - functional sequence protocol


    use FP::Predicates qw(is_sequence is_proper_sequence);
    # ^ placed here because we can't export functions from
    #     FP::Abstract::Sequence
    use FP::PureArray;
    use FP::StrictList;
    use FP::List;
    use FP::Stream;
    use FP::Array 'array';

    use FP::Equal 'is_equal';

    is_equal list(purearray(3, 4), 
                  strictlist(3, 4), 
                  list(3, 4), 
                  stream(3, 4), 
                  cons(3, 4), 
                  array(3, 4),  # Should we change this given `FP::autobox`?
                  {3 => 4})->map(\&is_sequence),
             list(1, 1, 1, 1, 1, undef, undef, undef);

    is is_sequence(cons 3, 4), 1;
    is is_proper_sequence(cons 3, 4), 0; # improper list

    my $ns = purearray(FP::Abstract::Sequence->FP_Interface__method_names);
    #  The methods you can count on being supported by sequences.

    is_equal $ns->sort->take(5),
             purearray('any', 'append', 'array', 'cons', 'drop');


This is a functional protocol, i.e. its use does not exert any side effects (that are visible to the user). It does *not* imply `FP::Abstract::Pure`, though; impure data structures could implement it all the same (in addition to a mutation protocol).




This is alpha software! Read the status section in the package README or on the website.