Generator/Exponential: Difference between revisions
Content deleted Content added
added Fantom example |
Updated both D entries |
||
Line 686:
=={{header|D}}==
===Ranges-Based
<lang d>import std.stdio, std.bigint, std.range, std.algorithm;
struct Filtered(R1, R2) if (is(ElementType!R1 == ElementType!R2)) {
R1 s1;
R2 s2;
Line 705 ⟶ 704:
const bool empty = false;
@property T front() { return current; }
void popFront() { _next(); }
Line 731 ⟶ 730:
}
struct
const bool empty = false;
void popFront() { /* n++; */ n += 1; }
}
Count!T count(T)(T start) { return Count!T(start); }
Count!T count(T)() { return Count!T(cast(T)0); }
void main() {
auto squares =
auto cubes =
auto f = filtered(squares, cubes);
popFrontN(f, 20);
writeln(take(f, 10));
}</lang>
{{out}}
<pre>[529, 576, 625, 676, 784, 841, 900, 961, 1024, 1089]</pre>
===Closures-Based Version===
{{trans|Go}}
<lang d>import std.stdio;
auto powers(in double e) pure nothrow {
double i = 0.0;
return
}
Line 782 ⟶ 786:
writeln();
}</lang>
{{out}}
<pre>529 576 625 676 784 841 900 961 1024 1089 </pre>
|