Created
April 2, 2014 12:23
-
-
Save pandaman64/9933038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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