NAME
Collections::Sorted - Easy to use iterator with sorted elements
VERSION
Version 0.01
SYNOPSIS
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
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
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
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
Mariano Wahlmann, <dichoso at gmail.com>
BUGS
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
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.