CLEAN limit impl

This commit is contained in:
Yadunand Prem 2022-11-02 11:16:17 +08:00
parent 852f48d522
commit b9ae7cfff2

View File

@ -60,19 +60,10 @@ public class InfiniteList<T> {
return InfiniteList.end();
}
/*
* next tail ->
* get the current tail
* check if actually.err(). If actually.err() then return limit(n). If ok()
* return limit - 1
*/
Memo<InfiniteList<T>> tail = Memo.from(() -> {
if (this.head.get().unless(null) == null) {
return this.tail.get().limit(n);
}
return this.tail.get().limit(n - 1);
});
Memo<InfiniteList<T>> tail = Memo.from(
() -> this.head.get()
.transform(h -> this.tail.get().limit(n - 1))
.except(() -> this.tail.get().limit(n)));
return new InfiniteList<>(this.head, tail);
}