![]() |
![]()
| ![]() |
![]()
NAMEDR::Tarantool::Iterator - an iterator and a container class for DR::TarantoolSYNOPSISuse DR::Tarantool::Iterator; my $iter = DR::Tarantool::Iterator->new([1, 2, 3]); my $item0 = $iter->item(0); my @all = $iter->all; my $all = $iter->all; while(my $item = $iter->next) { do_something_with_item( $item ); } METHODSnewA constructor.Arguments
clone(%opt)Clone the iterator object, but do not clone the tuples. This method can be used to create an iterator that has a different item_class and (or) item_constructor.If clone_items argument is true, the function clones the tuple list as well. my $iter1 = $old_iter->clone(item_class => [ 'MyClass', 'new' ]); my $iter2 = $old_iter->clone(item_class => [ 'MyClass', 'new' ], clone_items => 1); $old_iter->sort(sub { $_[0]->name cmp $_[1]->name }); # $iter1 is sorted, too, but $iter2 is not countReturn the number of tuples available through the iterator.itemReturn one tuple from the iterator by its index (or croak an error if the index is out of range).raw_itemReturn one raw tuple from the iterator by its index (or croak error if the index is out of range).In other words, this method ignores item_class and item_constructor. raw_sort(&)Sort the contents referred to by the iterator (changes the current iterator object). The compare function receives two raw objects:$iter->raw_sort(sub { $_[0]->field cmp $_[1]->field }); sort(&)Sort the contents referred to by the iterator (changes the current object). The compare function receives two constructed objects:$iter->sort(sub { $_[0]->field <=> $_[1]->field }); grep(&)Find all objects in the set referred to by the iterator that match a given search criteria (linear search).my $admins = $users->grep(sub { $_[0]->is_admin }); raw_grep(&)Same as grep, but works on raw objects.my $admins = $users->raw_grep(sub { $_[0]->is_admin }); getAn alias for item method.existsReturn true if the iterator contains a tuple with the given index.my $item = $iter->exists(10) ? $iter->get(10) : somethig_else(); nextReturn the next tuple, or undef in case of eof.while(my $item = $iter->next) { do_something_with( $item ); } Index of the current tuple can be queried with function 'iter'. iterReturn index of the tuple at the current iterator position.resetReset iteration index, return the previous value of the index.allReturn all tuples available through the iterator.my @list = $iter->all; my $list_aref = $iter->all; my @abc_list = map { $_->abc } $iter->all; my @abc_list = $iter->all('abc'); # the same my @list = map { [ $_->abc, $_->cde ] } $iter->all; my @list = $iter->all('abc', 'cde'); # the same my @list = map { $_->abc + $_->cde } $iter->all; my @list = $iter->all(sub { $_[0]->abc + $_->cde }); # the same item_classSet/return the tuple class. If the value is defined, the iterator blesses tuples with it (and also calls item_constructor if it is set).item_constructorSet/return the tuple constructor. The value is used only if item_class is defined.pushPush a tuple into the iterator.dataReturn/set an application-specific context maintained in the iterator object. This can be useful to pass additional state to item_constructor.
|