make flatten() support nulls

This commit is contained in:
Gregory.Shrago
2017-02-16 23:27:23 +03:00
parent a79c698b1d
commit c1b4f4713a
2 changed files with 7 additions and 1 deletions
@@ -304,6 +304,11 @@ public class TreeTraverserTest extends TestCase {
}
}
public void testFlatten() {
JBIterable<Integer> it = JBIterable.generate(1, INCREMENT).take(3).flatten(i -> i % 2 == 0 ? null : JBIterable.of(i - 1, i));
assertEquals(Arrays.asList(0, 1, 2, 3), it.toList());
}
public void testStatefulFilter() {
JBIterable<Integer> it = JBIterable.generate(1, INCREMENT).take(5).filter(new JBIterable.StatefulFilter<Integer>() {
int prev;
@@ -391,7 +391,8 @@ public abstract class JBIterable<E> implements Iterable<E> {
public T nextImpl() {
if (cur != null && cur.hasNext()) return cur.next();
if (!iterator.hasNext()) return stop();
cur = fun.fun(iterator.next()).iterator();
Iterable<? extends T> next = fun.fun(iterator.next());
cur = next == null ? null : next.iterator();
return skip();
}
};