www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9119] New: Forward range addition to associative arrays.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9119

           Summary: Forward range addition to associative arrays.
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: maidenphil hotmail.com



PST ---
Providing a forward range to associative arrays would allow user to use
functionalities like "filter" and make their own (that return intelligent
ranges instead of eagerly constructing a result, then returning said result or
a range on it). It could be provided as a "range" property and "front" could
return an entry struct where entry.key is the key and entry.value is the value.

Example usage:
float[ Item ] itemsCost;
auto cheapItems = itemsCost.range.filter!"a.value < 5"();
foreach( cheap; cheapItems ) {
  sendGiftToEnemy( cheap.key );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9119


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



See Issue 5075

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9119


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |hsteoh quickfur.ath.cx



https://github.com/D-Programming-Language/druntime/pull/574

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 15 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9119




Using the code in the pull request, this code works:

import std.algorithm;
import std.conv;
import std.stdio: writeln;
void main () {
        int[string] aa;
        aa["a"] = 1;
        aa["b"] = 2;
        aa["c"] = 3;
        writeln(aa.byPair
                .map!((a) => "key=" ~ a.key ~ " value=" ~ to!string(a.value))
                .joiner("\n")
        );
}


The output is:

key=a value=1
key=b value=2
key=c value=3

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 15 2013