Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/First-class-functions/D/first-class-functions-1.d
Normal file
9
Task/First-class-functions/D/first-class-functions-1.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
void main() {
|
||||
import std.stdio, std.math, std.typetuple, std.functional;
|
||||
|
||||
alias dir = TypeTuple!(sin, cos, x => x ^^ 3);
|
||||
alias inv = TypeTuple!(asin, acos, cbrt);
|
||||
// foreach (f, g; staticZip!(dir, inv))
|
||||
foreach (immutable i, f; dir)
|
||||
writefln("%6.3f", compose!(f, inv[i])(0.5));
|
||||
}
|
||||
18
Task/First-class-functions/D/first-class-functions-2.d
Normal file
18
Task/First-class-functions/D/first-class-functions-2.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
void main() {
|
||||
import std.stdio, std.math, std.range;
|
||||
|
||||
static T delegate(S) compose(T, U, S)(in T function(in U) f,
|
||||
in U function(in S) g) {
|
||||
return s => f(g(s));
|
||||
}
|
||||
|
||||
immutable sin = (in real x) pure nothrow => x.sin,
|
||||
asin = (in real x) pure nothrow => x.asin,
|
||||
cos = (in real x) pure nothrow => x.cos,
|
||||
acos = (in real x) pure nothrow => x.acos,
|
||||
cube = (in real x) pure nothrow => x ^^ 3,
|
||||
cbrt = (in real x) /*pure*/ nothrow => x.cbrt;
|
||||
|
||||
foreach (f, g; [sin, cos, cube].zip([asin, acos, cbrt]))
|
||||
writefln("%6.3f", compose(f, g)(0.5));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue