[Issue 17201] New: std.array: invert (convenience method that inverts a hashmap)
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Feb 19 14:17:51 PST 2017
https://issues.dlang.org/show_bug.cgi?id=17201
Issue ID: 17201
Summary: std.array: invert (convenience method that inverts a
hashmap)
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: greeenify at gmail.com
This is often used and could potentially be implemented in a more performant
way than the naive solution:
auto invert(A)(A a)
{
import std.algorithm.iteration : map;
import std.array;
import std.typecons : tuple;
auto a = [0:"a", 1:"b", 2:"c"];
return a.byKeyValue.map!(pair => tuple(pair.value, pair.key)).assocArray;
}
--
More information about the Digitalmars-d-bugs
mailing list