| Collections documentation | view source | Contained in the Collections distribution. |
Collections::Sorted - Easy to use iterator with sorted elements
Version 0.01
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;
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
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;
Read Collections::Ordered
Read Collections::Ordered
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
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] });
Returns an Collections::Ordered with the same elements of this collection
my $col = $collection->to_ordered;
Mariano Wahlmann, <dichoso at gmail.com>
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 2009 Mariano Wahlmann, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Collections documentation | view source | Contained in the Collections distribution. |