[REBOL] Re: Is unique buggy?
From: carl:cybercraft at: 13-Aug-2002 20:47
On 13-Aug-02, Louis A. Turk wrote:
> Hi Gregg,
> At 11:59 PM 8/12/2002 -0600, you wrote:
>> Hi Louis,
>>
>> << Does unique not work with objects? >>
>>
>> I think not.
> I just did some testing, and you are right. Disappointing! Well
> then, how does one make a unique function that will work with
> objects? Has someone already done this?
Thought a bit more about it Louis, and as third returns an object's
block, (or at least simple objects, anyway), using third instead of
mold would be a bit more efficient, though you'd still have to
convert the blocks back to objects afterwards. Example...
>> obj1: make object! [a: 10 b: "abc"]
>> obj2: make object! [a: 10 b: "abc"]
>> obj3: make object! [a: 10 b: "abcd"]
>> unique reduce [obj1 obj2 obj3]
== [
make object! [
a: 10
b: "abc"
]
make object! [
a: 10
b: "abc"
]
make obj...
>> unique reduce [third obj1 third obj2 third obj3]
== [[a: 10 b: "abc"] [a: 10 b: "abcd"]]
This also has the advantage of retaining the indexes of series...
>> obj2/b: next obj2/b
== "bc"
>> blk: unique reduce [third obj1 third obj2 third obj3]
== [[a: 10 b: "abc"] [a: 10 b: "bc"] [a: 10 b: "abcd"]]
>> blk/2/4
== "bc"
>> head blk/2/4
== "abc"
--
Carl Read