On Wednesday, 4 December 2024 at 08:50:21 UTC, axricard wrote:
Hello
I believe std.functional.partial can only apply to the first
argument.
Is there an equivalent for the Nth argument ?
Something like :
``` D
int fun(int a, int b) { return a - b; }
// create a function with the argument n°1 being equal to 5
// fun5 = fun(a, 5);
alias fun5 = partialN!(fun, 1, 5);
writeln(fun5(7)); // print 2
```
nothin Im aware of in the std but I think this is trivail
```d
import std;
template partialN(alias F,int arg,argvalue...){
auto partialN(T...)(T
otherargs)=>F(otherargs[0..arg],argvalue[0],otherargs[arg..$]);
}
unittest{
int fun(int a, int b) { return a - b; }
// create a function with the argument n°1 being equal to 5
// fun5 = fun(a, 5);
alias fun5 = partialN!(fun, 1, 5);
writeln(fun5(7));
}
```