[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Key-Value Operators on Array
From: |
Tom Hageman |
Subject: |
Re: Key-Value Operators on Array |
Date: |
Fri, 7 May 2004 00:05:54 +0200 |
Ach, I was a bit too trigger-happy on the Deliver button (and confused
about which mailinglist it was being sent to, as you probably can tell
:-/)
On Thu, 6 May 2004 23:59:52 +0200, I wrote:
> Hi Philip,
>
> On Thu, 6 May 2004 18:37:12 +0200, Philip Motteli wrote:
> > Hi
> >
> >
> > Usually, every key-value operation, that is applied to an array, is
> > applied to its contents. So the array is actually transparent.
> > There are certain exceptions though:
> >
> > @avg
> > @count
> > @distinctUnionOfArrays
> > @distinctUnionOfObjects
> > @max
> > @min
> > @sum
> > @unionOfArrays
> > @unionOfObjects
> >
> >
> > They are all marked by a preceding '@'. All these operators are sent
> > to> the array object itself and not to the objects it contains.
> >
> > My question, proposal is: Why not use this '@' as a general mark, that
> > an operator should be sent to the array itself? Not restrict its use
> > to> these few mentionned predefined operators? This wouldn't be a
> > problem for code written for Cocoa. Cocoa would just> not have that
> > feature and (probably) raise an exception.
> >
> > Or is there perhaps another way to do that and I'm just missing
> > something?
>
> In a previous incarnation (EOF) of key-value coding you could add
> -compute<Name>ForKey: methods in a category of NSArray, and these would
> be made available as "@<name>" operators in -valueForKeyPath:
>
> For example, one could implement:
>
> @interface NSArray(MyCategory)
> - (id)computeAtForKey:(NSString *)aKey;
> ...
>
> such that it can subsequently be used like:
>
> secondElement = [anArray valueForKeyPath:@"@at.2"];
>
> or
>
> nameOfThirdElement = [anArray valueForKeyPath:@"@at.3.name"];
>
>
> I haven't checked that if this mechanism still works in the Mac OS X
> 10.3 Cocoa incarnation though...
...or if it works at all in the GNUstep incarnation.
--
__/__/__/__/ Tom Hageman <trh@xs4all.nl> (home) [NeXTmail/Mime OK]
__/ __/_/ <t.hageman@proteon.nl> (work) [Mime OK]
__/__/__/
__/ _/_/ [ObjC retain];
objc: FREED(id): message retain sent to freed object=0xdeadcafe