On Fri, 23 Jan 2004, Marcus Boerger wrote:

> Fixed too. Hey if you find some cool & easy examples please tell me.

Thanks for the fix. I'll let you know when I come up with something
cool. :)

> Lukas already mentioned some random iterator. That would require an
> interface that add a count() method to the Seekable interface. And
> an iterator class that randomly seeks and reads from such interfaces.
> Of course the class would need to build up an array of available indices
> and only return elements not read so far by dropping any read index from
> the available list when read.

This is definitely nice. A reverse iterator could also be useful.

Right now, I am having problems combining FilterIterator with
ArrayIterator. (I am just exploring how everything works and starting
with basic examples.) I want to do something like:

class ArrayFilterIterator extends FilterIterator {
  protected $n;

  function __construct($a, $n) {
    parent::__construct(new ArrayIterator($a));
    $this->n = $n;
  }

  function accept() {
    return $this->current() >= $this->n;
  }
}

$a = array('a' => 1, 'b' => 2, 'c' => 3);
foreach (new ArrayFilterIterator($a) as $k => $v) {
  print "$k: $v\n";
}

But ArrayIterator has a private constructor, so that doesn't work. I
tried passing an ArrayObject, but then I get a message that I need to
pass an Iterator.

-adam

-- 
[EMAIL PROTECTED]
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to