Correct use of map
bearophile
bearophileHUGS at lycos.com
Fri Jan 3 12:07:33 PST 2014
Dfr:
> Here is few code eaxamples, i don't know why it is doesn't work
> as expected.
>
> Here i want to transform string into list of tuples split by
> character:
>
> auto nameparts = splitter("go.home", '.').map!(v =>
> tuple(v,0)).array;
>
> This gives me not very useful message about assert and stuff:
> core.exception.AssertError at std.algorithm(1942): Assertion
> failure
It works for me:
void main() {
import std.stdio, std.algorithm, std.typecons, std.range;
auto nameParts = "go.home"
.splitter('.')
.map!(v => tuple(v, 0))
.array;
nameParts.writeln;
}
Output:
[Tuple!(string, int)("go", 0), Tuple!(string, int)("home", 0)]
I am using dmd 2.065alpha on Windows.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list