Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created July 20, 2024 00:31
Show Gist options
  • Save crazymonkyyy/2491f95bdede35d8d5f38a7aefb77137 to your computer and use it in GitHub Desktop.
Save crazymonkyyy/2491f95bdede35d8d5f38a7aefb77137 to your computer and use it in GitHub Desktop.
auto curryrecurse(alias F,int I=2,Args...)(Args args){
static if(Args.length>I){
static if(is(typeof(F(args[0..I]))==void)){
F(args[0..I]);
curryrecurse!(F,I)(args[I..$]);
} else {
return curryrecurse!(F,I)(F(args[0..I]),args[I..$]);
}} else {
return F(args);
}}
unittest{
struct pair(T,S){
T a;
S b;
}
pair!(int,string)[] store;
void add(int i,string s){
store~=pair!(int,string)(i,s);
}
curryrecurse!add(2,"foo",3,"fizz",5,"buzz",7,"bar");
import std;
store.writeln;
}
unittest{
int n=42;
string fizzbuzz(string acc,int i,string app){
if(n%i==0)acc~=app;
return acc;
}
import std;
curryrecurse!(fizzbuzz,3)("",2,"foo",3,"fizz",5,"buzz",7,"bar").writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment