@Override public boolean isEmpty() { return string.isEmpty(); }
@Override public boolean isEmpty() { return bucket.isEmpty(); }
@Override public boolean isEmpty() { return ref.get().isEmpty(); }
default LazySeq<T> drop(final long num) { return defer(()-> { LazySeq<T> current = this; long pos = num; while (pos-- > 0 && !current.isEmpty()) { current = current.foldLazySeq(c -> c.tail.get(), nil -> nil); } return current; }); } default LazySeq<T> reverse() {
default LazySeq<T> dropWhile(Predicate<? super T> p) { return defer(()-> { LazySeq<T> current = this; boolean[] found = {false}; while (!found[0] && !current.isEmpty()) { LazySeq<T> active = current; current = current.foldLazySeq(c -> { if (!p.test(c.head.get())) { found[0] = true; return active; } return c.tail.get(); }, empty -> empty); } return current; }); } default LazySeq<T> drop(final long num) {
public <R> R lazyFoldRight(R zero, BiFunction<? super T,Supplier<R>, ? extends R> f){ long inc = 500; LazySeq<T> host = this; long count = inc; LazySeq<T> next = host.take(count); if(next.isEmpty()) return zero; Tuple2<Boolean,R> value = Tuple.tuple(true,zero); while(!next.isEmpty() && value._1()) { Cons<T> cons = next.foldLazySeq(c -> c, n -> null); value = cons.lazyFoldRightImpl(value._2(), f); next = host.drop(count).take(inc); count = count + inc; } return value._2(); }
@Test public void laziness(){ boolean empty = LazySeq.generate(()->1) .filter(i -> false) .take(0) .isEmpty(); System.out.println("Empty ? " + empty); /** assertTrue(LazySeq.generate(()->1).filter(i -> false).take(0).isEmpty()); assertTrue(LazySeq.generate(()->1).flatMap(i -> LazySeq.empty()).take(0).isEmpty()); **/ }
public LazySeq<LazySeq<T>> levels() { ReactiveSeq<LazySeq<T>> res = ReactiveSeq.iterate(LazySeq.of(this), sf -> sf.flatMap(a -> a.subForest())) .takeWhile(l -> !l.isEmpty()) .map(xs -> xs.map(x -> x.head)); return LazySeq.fromStream(res); }
@Override public boolean isEmpty() { return string.isEmpty(); }
@Override public boolean isEmpty() { return bucket.isEmpty(); }
@Override public boolean isEmpty() { return ref.get().isEmpty(); }
default LazySeq<T> drop(final long num) { return defer(()-> { LazySeq<T> current = this; long pos = num; while (pos-- > 0 && !current.isEmpty()) { current = current.foldLazySeq(c -> c.tail.get(), nil -> nil); } return current; }); } default LazySeq<T> reverse() {
default LazySeq<T> dropWhile(Predicate<? super T> p) { return defer(()-> { LazySeq<T> current = this; boolean[] found = {false}; while (!found[0] && !current.isEmpty()) { LazySeq<T> active = current; current = current.foldLazySeq(c -> { if (!p.test(c.head.get())) { found[0] = true; return active; } return c.tail.get(); }, empty -> empty); } return current; }); } default LazySeq<T> drop(final long num) {
public <R> R lazyFoldRight(R zero, BiFunction<? super T,Supplier<R>, ? extends R> f){ long inc = 500; LazySeq<T> host = this; long count = inc; LazySeq<T> next = host.take(count); if(next.isEmpty()) return zero; Tuple2<Boolean,R> value = Tuple.tuple(true,zero); while(!next.isEmpty() && value._1()) { Cons<T> cons = next.foldLazySeq(c -> c, n -> null); value = cons.lazyFoldRightImpl(value._2(), f); next = host.drop(count).take(inc); count = count + inc; } return value._2(); }
public LazySeq<LazySeq<T>> levels() { ReactiveSeq<LazySeq<T>> res = ReactiveSeq.iterate(LazySeq.of(this), sf -> sf.flatMap(a -> a.subForest())) .takeWhile(l -> !l.isEmpty()) .map(xs -> xs.map(x -> x.head)); return LazySeq.fromStream(res); }