Collections::Sorted - Easy to use iterator with sorted elements


Collections documentation  | view source Contained in the Collections distribution.

Index


NAME

Top

Collections::Sorted - Easy to use iterator with sorted elements

VERSION

Top

Version 0.01

SYNOPSIS

Top

    use Collections::Sorted;

    # Ordered collection
    my $col = Collections::Sorted->new( sub { $_[0] <=> $_[1] } );

    $col->add(101);
    $col->add(102);

    # this will return 101
    print $col->first;

NOTES

Top

Sort blocks are expected to return -1, 0, 1 as default sort blocks on perl if your block only return two values that can cause bad sorted sets

CLASS METHODS

Top

new()

Returns a new instace of a sorted Collection, first argument passed is the sort block, if no argument passed it will use default sort block which is sub { $_[0] <=> $_[1] }

  my $collection = Collections::Sorted->new;

INSTANCE METHODS

Top

add

Read Collections::Ordered

add_all

Read Collections::Ordered

reverse()

reverse method doesn't make sense for sorted collections, because order is imposed, so it will return an ordered collection with elements in reverse order

sort_block($sub)

If passed with $sub changes the current sort block, it also re-sort the entire collection, if no arguments passed it returns the sort block

  $colection->sort_block( sub { $_[0] <=> $_[1]  });

to_ordered()

Returns an Collections::Ordered with the same elements of this collection

   my $col = $collection->to_ordered;

AUTHOR

Top

Mariano Wahlmann, <dichoso at gmail.com>

BUGS

Top

Please report any bugs or feature requests to dichoso at gmail.com. I will be notified, and then you'll be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


Collections documentation  | view source Contained in the Collections distribution.