www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - .byKeyValue should probably return a Tuple

reply Yuxuan Shui <yshuiv7 gmail.com> writes:
for(k, v; aa) { ... } is better than:

for(o; aa) {
     auto k = o.key, v = o.value;
     ...
}

right?

Are there any reason why .byKeyValue doesn't return a Tuple?
Feb 15 2017
parent reply Seb <seb wilzba.ch> writes:
On Wednesday, 15 February 2017 at 21:54:20 UTC, Yuxuan Shui wrote:
 for(k, v; aa) { ... } is better than:

 for(o; aa) {
     auto k = o.key, v = o.value;
     ...
 }

 right?

 Are there any reason why .byKeyValue doesn't return a Tuple?
There's byPair (http://dlang.org/phobos/std_array.html#byPair) that as a library does exactly the following: ``` a.byKeyValue.map!(pair => tuple(pair.key, pair.value)) ```
Feb 15 2017
parent reply Yuxuan Shui <yshuiv7 gmail.com> writes:
On Wednesday, 15 February 2017 at 22:02:01 UTC, Seb wrote:
 On Wednesday, 15 February 2017 at 21:54:20 UTC, Yuxuan Shui 
 wrote:
 for(k, v; aa) { ... } is better than:

 for(o; aa) {
     auto k = o.key, v = o.value;
     ...
 }

 right?

 Are there any reason why .byKeyValue doesn't return a Tuple?
There's byPair (http://dlang.org/phobos/std_array.html#byPair) that as a library does exactly the following: ``` a.byKeyValue.map!(pair => tuple(pair.key, pair.value)) ```
Thanks! It should be more visible though. Can we include it here: https://dlang.org/spec/hash-map.html ?
Feb 15 2017
parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Thu, Feb 16, 2017 at 05:02:41AM +0000, Yuxuan Shui via Digitalmars-d wrote:
 On Wednesday, 15 February 2017 at 22:02:01 UTC, Seb wrote:
 On Wednesday, 15 February 2017 at 21:54:20 UTC, Yuxuan Shui wrote:
 for(k, v; aa) { ... } is better than:
 
 for(o; aa) {
     auto k = o.key, v = o.value;
     ...
 }
 
 right?
 
 Are there any reason why .byKeyValue doesn't return a Tuple?
There's byPair (http://dlang.org/phobos/std_array.html#byPair) that as a library does exactly the following: ``` a.byKeyValue.map!(pair => tuple(pair.key, pair.value)) ```
Thanks! It should be more visible though. Can we include it here: https://dlang.org/spec/hash-map.html ?
Please file a bug against dlang.org to request this doc update, so that people won't forget to do it. Thanks! T -- It's amazing how careful choice of punctuation can leave you hanging:
Feb 15 2017
parent reply Seb <seb wilzba.ch> writes:
On Thursday, 16 February 2017 at 05:20:32 UTC, H. S. Teoh wrote:
 On Thu, Feb 16, 2017 at 05:02:41AM +0000, Yuxuan Shui via 
 Digitalmars-d wrote:
 On Wednesday, 15 February 2017 at 22:02:01 UTC, Seb wrote:
 On Wednesday, 15 February 2017 at 21:54:20 UTC, Yuxuan Shui 
 wrote:
 [...]
There's byPair (http://dlang.org/phobos/std_array.html#byPair) that as a library does exactly the following: ``` a.byKeyValue.map!(pair => tuple(pair.key, pair.value)) ```
Thanks! It should be more visible though. Can we include it here: https://dlang.org/spec/hash-map.html ?
Please file a bug against dlang.org to request this doc update, so that people won't forget to do it. Thanks! T
Or just do it yourself - it's not that difficult: https://github.com/dlang/dlang.org/edit/master/spec/hash-map.dd
Feb 16 2017
parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Thu, Feb 16, 2017 at 08:43:57AM +0000, Seb via Digitalmars-d wrote:
 On Thursday, 16 February 2017 at 05:20:32 UTC, H. S. Teoh wrote:
 On Thu, Feb 16, 2017 at 05:02:41AM +0000, Yuxuan Shui via Digitalmars-d
 wrote:
 On Wednesday, 15 February 2017 at 22:02:01 UTC, Seb wrote:
[...]
 There's byPair (http://dlang.org/phobos/std_array.html#byPair)
 that as a library does exactly the following:
 ```
 a.byKeyValue.map!(pair => tuple(pair.key, pair.value))
 ```
Thanks! It should be more visible though. Can we include it here: https://dlang.org/spec/hash-map.html ?
Please file a bug against dlang.org to request this doc update, so that people won't forget to do it. Thanks! T
Or just do it yourself - it's not that difficult: https://github.com/dlang/dlang.org/edit/master/spec/hash-map.dd
Well, I didn't have time to fix it then, and I almost forgot about it. But luckily I kept this thread alive in my mail reader, so here it is: https://github.com/dlang/dlang.org/pull/1573 T -- People say I'm indecisive, but I'm not sure about that. -- YHL, CONLANG
Feb 17 2017