Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Searching objects

From: carl::cybercraft::co::nz at: 14-Dec-2001 0:46

On 13-Dec-01, Robert M. Muench wrote:
> Hi, I have the following problem: > I'm handling objects, with several data-fields, in a series and now > want to find an object with a specific value in a data-field. The > problem is that 'find doesn't browse through the values. > Any tip how I can search for values in data-fields of objects? > Robert
The following function might do the job for you, though I's sure there must be a better way... obj-find: func [series field value][ forall series [if series/1/:field = value [return index? series]] none ] s: reduce [ make object! [a: 10 b: "a"] make object! [a: 20 b: "b"] make object! [a: 30 b: "c"] make object! [a: 40 b: "d"] ]
>> obj-find s 'a 20
== 2
>> obj-find s 'a 50
== none
>> obj-find s 'b "d"
== 4 -- Carl Read