a unidirectional range filter can be implimented as simply as:
auto find(alias F,R)(R r){
while( ! r.empty && ! F(r.front)){
r.popFront;
}
return r;
}
unittest{
counter(5).find!(a=>a==3).summery;
}
auto findnext(alias F,R)(R r){
r.popFront;
return r.find!F;
}
auto filter(alias F,R)(R r){
struct Filter{
R r;
auto ref front()=>r.front;
void popFront(){r=r.findnext!F;}
bool empty()=>r.empty;
}
return Filter(r.find!F);
}
unittest{
counter(10).filter!(a=>a%3).summery;//[1, 2, 4, 5, 7, 8]
}
Im aware phoboes takes ....more complexity to implement filter and there should be some extra complexity to make a bidirectional filter, but when I ussally look into phoboes 1000 line functions I usually make different tradeoffs. What are the actual considerations here?