Convert little imperative code to functional coding style

Timon Gehr timon.gehr at gmx.ch
Sun Aug 12 12:44:32 PDT 2012


On 08/10/2012 09:59 PM, Nathan M. Swan wrote:
> On Friday, 10 August 2012 at 18:26:56 UTC, Timon Gehr wrote:
>> Is this what you are looking for?
>>
>> import std.stdio;
>> import std.range : iota;
>> import std.algorithm : map, filter, joiner;
>> import std.typecons : tuple;
>> import std.math : sqrt, floor;
>>
>> void main(){
>> immutable limit = cast(size_t)floor(sqrt(1_000.0));
>>
>> auto r = iota(2,limit).map!(m=>iota(1,m-1).map!(n=>tuple(m,n))).joiner
>> .filter!(t=>2*t[0]*(t[0]+t[1])==1_000)
>> .map!(t=>(t[0]^^4-t[1]^^4)*(2*t[0]*t[1]));
>>
>> writeln(r.front);
>> }
>
> Ugh! I guess functional isn't always the best ;)
>

In an attempt to destroy that guess I have uncovered the following
compiler bug: http://d.puremagic.com/issues/show_bug.cgi?id=8542


More information about the Digitalmars-d-learn mailing list