partially working takeWhile

This commit is contained in:
Yadunand Prem
2022-11-02 16:15:06 +08:00
parent 3682230f6c
commit 345acc6329

View File

@@ -72,8 +72,8 @@ public class InfiniteList<T> {
Memo<InfiniteList<T>> tail = Memo.from(() -> { Memo<InfiniteList<T>> tail = Memo.from(() -> {
// if head is err, then return return end // if head is err, then return return end
return head.get() return head.get()
.transform(h -> this.tail.get().takeWhile(pred)) .transform(h -> this.tail().takeWhile(pred))
.except(() -> InfiniteList.end()); .unless(InfiniteList.end());
}); });
return new InfiniteList<>(head, tail); return new InfiniteList<>(head, tail);
@@ -87,14 +87,14 @@ public class InfiniteList<T> {
} }
public <U> U reduce(U id, Combiner<U, U, ? super T> acc) { public <U> U reduce(U id, Combiner<U, U, ? super T> acc) {
// TODO // reduce by applying this.head to acc, this.tail.head to acc,
this.tail().reduce(acc.combine(id, this.head()), acc); // this.tail.tail.head to acc, until finally id to acc
// return acc.combine(this., acc)
return null; return null;
} }
public long count() { public long count() {
// TODO return this.reduce(0L, (a, b) -> a + 1);
return 0L;
} }
@Override @Override