FP::Abstract::Compare - comparison protocol
package FPCompareExample::Foo { use FP::Struct ["num"]; sub FP_Compare_compare { my ($a, $b) = @_; # let's make the default sort order reversed for the sake # of a more interesting example: $b->num cmp $a->num } _END_ } use FP::PureArray; use FP::Ops 'the_method'; use FP::Equal qw(is_equal); is_equal( purearray(2,3,-7,4,2,8) ->map(\&FPCompareExample::Foo::c::Foo) ->sortCompare ->map(the_method("num")), purearray(8, 4, 3, 2, 2, -7));
Objects implementing this protocol can be ordered unambiguously.
The `$a->FP_Compare_compare($b)` returns -1 if $a is to be ordered before $b (is smaller), 0 if they are to be ordered into the same position, 1 if $a is to be ordered after $b.
This method is used for the default sort order by the `sort` method offered on sequences.
FP::Compare
This is alpha software! Read the status section in the package README or on the website.
To install FunctionalPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FunctionalPerl
CPAN shell
perl -MCPAN -e shell install FunctionalPerl
For more information on module installation, please visit the detailed CPAN module installation guide.