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

[REBOL] Re: COLLECTing results

From: brett::codeconscious::com at: 29-Nov-2003 0:44

Interesting versions. I first thought of collect when I was thinking about map. One downside of map is that generally it requires a simple series as input, whereas looping functions can have more flexibile iterations. Map also often needs to be given a custom function which seems like overkill. The main thing that map is useful for is the accumulation of the result. With collect I wanted just the good bit of map. Unfortunately collect cannot always replace map. When the series of items is empty, map returns an empty block, collect will not provide a result (not even an empty block) because it doesn't get called at all. The result in this case is whatever the looping function returns when it doesn't do anything Eg. repeat i 0 collect [i] foreach x [] collect [x] So some application code might be needed to handle that case - unless you pass in a pre-existing series using /initial. So I got the good bit with collect but with an unwelcome cost! You win some, you lose some. :-/ Regards, Brett.