Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7319 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60989 invoked by uid 1010); 24 Jan 2004 20:13:16 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 60945 invoked from network); 24 Jan 2004 20:13:16 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 24 Jan 2004 20:13:16 -0000 Received: (qmail 28234 invoked by uid 546); 24 Jan 2004 20:13:16 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 24 Jan 2004 20:13:16 -0000 Date: Sat, 24 Jan 2004 15:13:15 -0500 (EST) X-X-Sender: adam@miranda.org To: Marcus Boerger cc: internals@lists.php.net In-Reply-To: <4-1484044703.20040123234108@marcus-boerger.de> Message-ID: References: <127-1489258859.20040123221414@marcus-boerger.de> <4-1484044703.20040123234108@marcus-boerger.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] SPL Examples Broken? From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) 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 -- adam@trachtenberg.com author of o'reilly's php cookbook avoid the holiday rush, buy your copy today!