Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSEnumerator and the missing peek method




On 29 Sep 2005, at 22:09, John C. Randolph wrote:
On Sep 29, 2005, at 1:53 PM, Jan Vereecken wrote:
- Why didn't the AppKit developers include this (the hasNext method) in the first place?


Probably because you can't always tell if there is a next object until you try to obtain it. Remember, enumerators don't only traverse arrays. They might be going through sets, and I could write an enumerator that traverses a tree, which still behaves the same as all other enumerators

Precisely! For example, MPWFoundation provides filter-enumerators that obtain the next object by filtering their source enumerator. The filtering takes the form of selecting objects based on the return value of a method (in which case -nextObject has to run the source until it finds one that matches or reaches its end), or of just getting the return value of the method and returning that instead. Since each filter-enumerator provides the same interface it requires, they are arbitrarily stackable, though that capability is currently not exposed in the HOM-wrappers that are the primary interface to filter-enumerators.


Furthermore, a NSEnumerator doesn't have to actually be based on an underlying list, it might simply compute its values on the fly.

Marcel



--
Marcel Weiher                          Metaobject Software Technologies
email@hidden         www.metaobject.com
The simplicity of power            HOM, IDEAs, MetaAd etc.
        1d480c25f397c4786386135f8e8938e4


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSEnumerator and the missing peek method (From: Jan Vereecken <email@hidden>)
 >Re: NSEnumerator and the missing peek method (From: "John C. Randolph" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.