Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created March 7, 2025 22:29
Show Gist options
  • Save crazymonkyyy/a7b3295286594c45af975c585a226e22 to your computer and use it in GitHub Desktop.
Save crazymonkyyy/a7b3295286594c45af975c585a226e22 to your computer and use it in GitHub Desktop.
alias seq(T...)=T;
template groupby(alias F,A...){
template groupby(int I){
alias groupby=seq!();
static foreach(J,a;A){
static if(F(J)==I){
groupby=seq!(groupby,a);
}
}}
}
unittest{
import std;
alias foo=groupby!(a=>a%2,int,float,bool,1,2,3,13.37);
foo!0.stringof.writeln;
foo!1.stringof.writeln;
alias bar=groupby!(a=>a/3,int,float,bool,1,2,3,13.37);
bar!0.stringof.writeln;
bar!1.stringof.writeln;
bar!2.stringof.writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment