Problem with map, reduce, ..
Stefan via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 24 04:03:00 PDT 2015
On Wednesday, 24 June 2015 at 09:35:35 UTC, Adrian Matoga wrote:
> On Wednesday, 24 June 2015 at 08:58:10 UTC, Stefan wrote:
>> On Wednesday, 24 June 2015 at 08:33:29 UTC, Adrian Matoga
>> wrote:
>>> [...]
>>
>> Thanks! That does it!
>>
>> Any idea how to make the 'ugly' reduce step more 'pleasant'?
>> I.e. make it a part of the filter, map, .. chain?
>
> What about:
>
> auto result = File(test.ini", "r")
> .byLine()
> .filter!( line => !startsWith( line, "#" ) &&
> !startsWith( line, "!") && line.length > 0 )
> .map!( line => line.idup.split('='))
> .filter!( fields => fields.length > 1)
> .map!( fields => tuple(fields[0].strip(),
> fields[1].strip() ))
> .assocArray();
Wow! Very cool!
Thanks
More information about the Digitalmars-d-learn
mailing list