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

[REBOL] Re: Sorting an object based on one field.

From: brett:codeconscious at: 13-Jan-2002 11:43

Hi, SORT has a compare refinement. So use sort on the series but supply a function that will compare your objects. See "Comparison Functions" in "Sorting Series" of the Rebol/Core documentation. So using your example: dir: [] foreach file read %. [ info: info? file append dir make object! [date: info/date file_name: file] ] sort/compare dir func[a b][lesser? a/date b/date] We can make a function that sorts series given a field name: sort-object-series: func [ "Sorts a series of objects" series [series!] field [word!] ][ sort/compare series func[a b][lesser? get in a field get in b field] ] Now we can do this: sort-object-series dir 'date sort-object-series dir 'file_name Cheers Brett.