enumerate, and some improvements

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 27 13:51:05 PDT 2014


> ------------------
>
> And I'd like map/filter to accept arrays and associative 
> arrays, and not just functions:
>
> void main() {
>   import std.algorithm: map;
>   auto keys = [1, 2, 1, 1, 1];
>   auto a = [0, 10, 20];
>   auto r1 = map!(k => a[k])(keys); // OK
>   auto r2 = map!a(keys);           // Error
>   auto aa = [1: 10, 2: 20];
>   auto r3 = map!(k => aa[k])(keys); // OK
>   auto r4 = map!aa(keys);           // Error
> }
>
>
> This is a common idiom in Clojure. Arrays and associative 
> arrays can be seen as functions defined by an enumeration of 
> input-outputs.

This part of ER 8715 is coming from quickfur:
https://github.com/D-Programming-Language/phobos/pull/2556

Bye,
bearophile


More information about the Digitalmars-d mailing list