incubator-jena-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Seaborne <>
Subject Iter.mapMany
Date Tue, 27 Sep 2011 08:56:07 GMT

I took the liberty of rewriting the implementation of Iter.mapMany - it 
didn't cope with the case where one of the sub-iterators returned was 
zerolength because it created the iterator and immediately called .next().

The situation occurred in the SPARQL WG test suite  for Update, where a 
binding didn't generate any legal quads.(TemplateLib.calcQuads).

Where did the name "mapMany" come from?  It's called "flatMap in scala.

The implement of flatmap is shorter :-) ... and recursive (the while 
loop in mapMany is removing that tail recursion).



   def flatMap[B](f: A => GenTraversableOnce[B]): Iterator[B]
              = new Iterator[B] {
       private var cur: Iterator[B] = empty
       def hasNext: Boolean =
         cur.hasNext || self.hasNext &&
              { cur = f(; hasNext }
       def next(): B = (if (hasNext) cur else empty).next()

View raw message