How to instantiate a map with multiple functions
Fusxfaranto via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 26 11:38:16 PST 2015
On Saturday, 26 December 2015 at 19:30:24 UTC, karthikeyan wrote:
> How to instantiate a map with multiple functions. I looked into
> the docs at
> http://dlang.org/phobos/std_algorithm_iteration.html#map. They
> contain a string which I suppose is a mixin and when I change
> "a" to some other name it results in an error for me. Are there
> any ways to use lambda functions directly instead of strings
> and any explanation of the strings used in the map example and
> why a is used will be helpful.
>
> I tried reading the source
> https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L520 .Some hint that "a" should be used at https://github.com/D-Programming-Language/phobos/blob/master/std/functional.d#L101 but how do I change that since map doesn't allow me any params to specify the parameter name. Also how can I map an array of tuples with two or more elements with a function of two or more params like unpack the tuple into a function like that. I am D beginner so any will insights will be very helpful for me.
>
> I am using dmd version 2.069 on Linux Mint 15 - 64bit
You should be able to just use any function (including lambdas)
as a template argument to map. The string version is from before
the more concise "=>" lambda syntax was developed, and generally
isn't what you want to use nowadays.
More information about the Digitalmars-d-learn
mailing list