Skip to content

Instantly share code, notes, and snippets.

@pandaman64
Created April 2, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandaman64/9933038 to your computer and use it in GitHub Desktop.
Save pandaman64/9933038 to your computer and use it in GitHub Desktop.
import std.typecons;
import std.traits;
import std.stdio;
auto tupleAccumlate(Func,First,Types...)(Func func,First first,Types args){
static if(args.length > 0){
return tupleAccumlate(func,func(first,args[0]),args[1..$]);
}
else{
return first;
}
}
struct FilterFunctor(alias Pred){
auto opCall(Tuple,T)(Tuple t,T value){
static if(Pred!T){
return tuple(t.expand,value);
}
else{
return t;
}
}
}
auto tupleFilter(alias Pred,Types...)(Types args){
return tupleAccumlate(
FilterFunctor!Pred.init,
tuple(),
args
);
}
void main(){
tupleFilter!isIntegral(1,2,3,4,"huhu",5).writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment