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

NAME

FP::SortedPureArray

SYNOPSIS

use FP::PureArray;
use FP::SortedPureArray;
use FP::Equal qw(is_equal);
use FP::Ops qw(real_cmp);

my $a1 = purearray(10, 40, 50, 50, 60);

# This re-blesses $a1, too ($a1 and $s1 are the same object), so
# it's not a functional operation, but then it shouldn't be
# damaging either, or so one hopes...:
my $s1 = $a1->as_sorted_by(\&real_cmp);

is_equal [ $s1->perhaps_binsearch(40) ], [40];
is_equal [ $s1->perhaps_binsearch(41) ], [];
ok $s1->checks_ok;

*real_sortedpurearray = sortedpurearray_by(\&real_cmp);
my $vs = real_sortedpurearray(10, 40, 50, 50, 60);

is_equal [ $vs->perhaps_binsearch(40) ], [40];
is_equal [ $vs->perhaps_binsearch(41) ], [];
ok $vs->checks_ok;

# For performance reasons, the constructor does *not* sort the
# values or check whether the values are actually sorted.
my $bad = real_sortedpurearray(10, 50, 40, 60);

# But that check can be run explicitly:
ok not $bad->checks_ok;

ok real_sortedpurearray(10, 50, 50, 60)->checks_ok;

is sortedpurearray_by(\&real_cmp)->(10,10)->checks_ok, 1;
is sortedpurearray_by(\&real_cmp)->(20,10)->checks_ok, '';
is sortedpurearray_by(\&real_cmp)->(3,10)->checks_ok, 1;

DESCRIPTION

A sorted FP::PureArray. Has all the methods of the latter, plus currently just `perhaps_binsearch`.

So, this is very much unfinished and deserves more methods and constructors, as well as possibly a protocol (FP::Abstract::*).

SEE ALSO

FP::PureArray, that this inherits from.

NOTE

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