Hello,

Recently, I finally figured out just how great the Iter module is
(it's almost lazy lists!). There were two things that I find myself
using a lot which are not in the module though. Firstly, a version of
chain that takes an iterator returning iterators as its argument (as
opposed to multiple already existing iterators), so that the whole
process is truly lazy (ichain or maybe iconcat?). Seconldy, I often
want to iterate over strings, so an iteratorfactory for them is really
practical. Below is simple code demonstrating the idea, if there is
nothing against these I'd be happy to supply a proper patch &
documentation.

Regards,
Marijn

------

registerIteratorFactory("string", function(x){return typeof(x) ==
"string";}, function (string){
  var pos = 0;
  return {next: function() {
    if (pos < string.length) return string.charAt(pos++);
    else throw StopIteration;
  }};
});

function ichain(iterators){
  var current = iter([]);
  return {next: function (){
    try {
      return current.next();
    } catch (e) {
      if (e != StopIteration) throw e;
      current = iter(iterators.next());
      return arguments.callee();
    }
  }};
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" 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/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to