First-class functions: Difference between revisions

Content deleted Content added
m →‎{{header|Ruby}}: Line 9 is now line 6.
Line 478: Line 478:
foreach (i, f; dir)
foreach (i, f; dir)
writefln("%6.3f", compose!(f, inv[i])(0.5));
writefln("%6.3f", compose!(f, inv[i])(0.5));
}</lang>

=={{header|Dart}}==
<lang dart>cube(x) { return x * x * x; }
inv_cube(x) { return Math.pow(x, 1/3); }

compo(f1, f2) {
return func(x) { return f1(f2(x));};
}

main() {
var funcs = [Math.sin, Math.exp, cube];
var invs = [Math.asin, Math.log, inv_cube];
for (int i = 0; i < 3; i++)
print(compo(funcs[i], invs[i])(1));
}</lang>
}</lang>