Partial function application: Difference between revisions

Updated D version
(Updated D version)
Line 248:
<lang d>import std.stdio, std.algorithm, std.traits;
 
auto fs(alias f)(in int[] s) /*pure nothrow*/
if (isCallable!f && ParameterTypeTuple!f.length == 1) {
return map!f(s);
}
 
int f1(in int x) pure nothrow { return x * 2; }
int f2(in int x) pure nothrow { return x *^^ x2; }
 
alias fs!f1 fsf1;
Line 260:
 
void main() {
autoforeach d1 =(d; [[0, 1, 2, 3];, [2, 4, 6, 8]]) {
writeln(fsf1(d1d));
writeln(fsf2(d1d));
}
 
auto d2 = [2, 4, 6, 8];
writeln(fsf1(d2));
writeln(fsf2(d2));
}</lang>
Output:
Anonymous user