fix(util/lazy_list): bug in filter operation

This commit is contained in:
Leonardo de Moura 2014-09-12 14:58:13 -07:00
parent b7dcb8f833
commit b482f27543
2 changed files with 9 additions and 1 deletions

View file

@ -189,6 +189,13 @@ void tst5() {
display(take(10, l));
}
void tst6() {
auto l = mk_gen();
unsigned counter = 0;
for_each(filter(take(10, l), [](unsigned v) { return v % 2 == 0; }), [&](unsigned) { counter++; });
lean_assert(counter == 5);
}
int main() {
save_stack_info();
tst1();
@ -196,5 +203,6 @@ int main() {
tst3();
tst4();
tst5();
tst6();
return has_violations() ? 1 : 0;
}

View file

@ -174,7 +174,7 @@ lazy_list<T> filter(lazy_list<T> const & l, P && pred, char const * cname = "laz
if (!p) {
return p;
} else if (pred(p->first)) {
return p;
return some(mk_pair(p->first, filter(p->second, pred, cname)));
} else {
check_system(cname);
return filter(p->second, pred, cname).pull();