I was discussing an issue with Enumerable#grep with sam: currently, it only allows basic regex matching against elements' toString methods. The optional iterator is *not* for computing an alternate test value, but for computing an alternate *returned* value.
That's because grep was designed to mimic Ruby's Enumerable#grep method, which relies on the elements' === operator (match operator) to provide custom matching. What we figure is, we could emulate that in Prototype by assuming whatever gets passed as a first argument has a "match" method, which is passed the raw element (not its toString representation anymore) and returns true (or anything boolean-equivalent to true) if the element should be retained in the resultset. In order to ensure backward compatibility, we would turn string filters into RegExp objects, and provide RegExp with a "match" alias to its nominal "test" method. Note that you can pass it a raw element: it will, indeed, call its toString method (as per ECMA-262) in this case. Then we can envision using Selector objects as filters, too. And anything else that provides a match method. Obviously, if you're going to write your own predicate anyway, you may be better off with using select/findAll instead. The idea of this evolution of grep is to have it leverage existing "match" methods in objects, not to replace select/findAll. We're aiming at bringing it closer to its Ruby's namesake. I have a tested, working patch ready. But before I put it into Trac, I'd like your opinion. Sam and I feel this is good, but maybe you have 2 nice cents to contribute to the idea (e.g. other objects that do have match methods which could become useful de facto filters)? -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---
