On Thu, Feb 16, 2012 at 01:51:34PM -0500, John J. Foerch wrote: > Conceptually, it looks like a composition of functions, where a value of > null from any function in the chain returns null for the whole > composition. Instead of naming the arguments 'from' and 'to', the idea of > composing a transformation could be made explicit with a type signature: > > define_client_redirect(name, transform ...); > > Where all transforms get composed together. Each can be a regexp or a > function; the final result must be a string url. > > We would probably never need all that power, but maybe this way of looking > at it helps to explain the confusing type signature, and could guide the > documentation of the module.
That kind of implementation looks something like this: function define_client_redirect (name) { var transforms = Array.prototype.slice.call(arguments, 1); function transform (location) { for (var i = 0, n = transforms.length; i < n; ++i) { if (transforms[i] instanceof RegExp) { if (location instanceof Ci.nsIURI) var lstr = location.spec; else lstr = location; location = transforms[i].exec(lstr); } else location = transforms[i](location); if (location == null) return null; } return location; } redirects[name] = transform; } That's my kind of fun :) -- John Foerch _______________________________________________ Conkeror mailing list Conkeror@mozdev.org https://www.mozdev.org/mailman/listinfo/conkeror