GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Iterator::Simple::Lookahead(3) User Contributed Perl Documentation Iterator::Simple::Lookahead(3)

Iterator::Simple::Lookahead - Simple iterator with lookahead and unget

  use Iterator::Simple::Lookahead;
  my $iter = Iterator::Simple::Lookahead->new( sub {}, @values );
  my $first = $iter->peek();
  my $second = $iter->peek(1);
  my $next = $iter->next; # or $iter->()
  $iter->unget( sub {}, @values );

This module encapsulates an iterator function. An iterator function returns the next element in the stream on each call, and returns "undef" on end of input.

The iterator can return a code reference - this new iterator is inserted at the head of the queue.

The object allows the user to "peek()" the Nth element of the stream without consuming it, or to get it and remove from the stream.

A list of items can also be pushed back to the stream by "unget()", to be retrieved in the subsequent "next()" calls. The next item can also be retrieved by calling "$iter->()".

The input list to the constructor and to "unget()" contains items to be retrieved on each "next()" call, or code references to be called to extract the next item from the stream.

Other types of input can be converted to a code reference by "iter()" of Iterator::Simple.

This module is built on top of Iterator::Simple and returns iterators that are compatible with the former, i.e. an object of type "Iterator::Simple::Lookahead" can be used as an input to "iter()".

Creates a new object ready to retrieve elements from the given input list. The list contains either values to be returned in a subsequent "next()" call, or code references to be called to extract the next item from the stream.

Other types of input can be converted to a code reference by "iter()" of Iterator::Simple.

Retrieves the Nth-element at the head of the stream, but keeps it in the stream to be retrieved by "next()".

Calls the iterator function to compute the items up to the Nth element, returns "undef" if the stream is exhausted before reaching N.

As a special case, "peek()" retrieves the element at the head of the stream, or "undef" if the stream is empty.

Retrieves the element at the head of the stream and removes it from the stream.

Returns "undef" if the stream is empty

Pushes back a list of values and/or iterators to the stream, that will be retrieved on the subsequent calls to "next()".

Can be called from within an iterator, to insert values that will be returned before the current call, e.g. calling from the iterator:

  $stream->unget(1..3); return 4;

will result in the values 4,1,2,3 being returned from the stream.

None.

Paulo Custodio, "<pscust at cpan.org>"

Please report any bugs or feature requests through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Iterator-Simple-Lookahead>.

Inspired in HOP::Stream and Iterator::Simple.

Copyright (C) 2013 by Paulo Custodio

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.1 or, at your option, any later version of Perl 5 you may have available.

2019-03-03 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.