The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

XAS::Lib::Iterator - A class for the XAS environment

SYNOPSIS

 use XAS::Lib::Iterator;

 my @data = ['test1', 'test2', 'test3', 'test4'];
 
 my $iterator = XAS::Lib::Iterator->new(@data);

 while (my $item = $iterator->next) {

     printf("item: %s\n", $item);

 }

DESCRIPTION

This is a general purpose iterator for an array of items. Once the items are composed, you can then transverse over them and return items.

METHODS

new($items);

Initialize the object and process the supplied items.

$items

If the item is a blessed object with a as_list() method, then what is returned from that call is used.

If the item is a hash, it will be decomposed into an array of hashes with the fields "key" and "value". Where "key" is the orignal key and "value" is the original value. The items will be sorted by the key.

And lastly, you can use a delimited string. The delimiter can be white space or commas. This will be split into an array of sorted items.

Sorting is done by Perls builtin sort function.

count

Return the number of items.

first

Set the index to the first item.

last

Set the index to the last item.

index($position)

Return or set the current position of the index.

$position

The optional position within the index. This is ones based.

find($callback)

This method will find an item within the items. It will return the position in the index or -1.

$callback

The comparison routine. It is passed an item for comparision. The routine should return the following:

  • 1 if the item is greater then what is wanted.

  • -1 if the item is lesser then what is wanted.

  • 0 if they match.

next

Return the next item and increment the index.

prev

Return the previous item and decrements the index.

item

Return the item at the current index position.

items

Return a slice of the items from the current index position to the end.

SEE ALSO

XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (c) 2015 Kevin L. Esteb

This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.