import std.stdio, std.algorithm;auto unique(){ bool[int] c; return (int a){ if (a in c) return false; else{ c[a] = true; return true; } }; } void main() { [1, 5, 5, 2, 1, 5, 6, 6].filter!(unique()).writeln; }
Just add static to the closure.
auto unique(){
static bool[int] c;
return (int a){
if (a in c)
return false;
else{
c[a] = true;
return true;
}
};
}
