Key and value with ranges

christian.koestlin christian.koestlin at gmail.com
Tue Oct 3 20:50:01 UTC 2023


On Tuesday, 3 October 2023 at 20:22:30 UTC, Andrey Zherikov wrote:
> On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin 
> wrote:
>> On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov 
>> wrote:
>>> On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin 
>>> wrote:
>>>> [...]
>>>
>>> Slightly improved:
>>> ```d
>>> import std;
>>>
>>> [...]
>>
>> Thanks .. the thing with ref result is very clever!
>> Should `ref result` be `return result`?
>
> `ref` might not be necessary fo AA but I'm not sure.
I found this in regards to AAs: 
https://forum.dlang.org/post/baewchcnyfibkvuiyybj@forum.dlang.org
So it might be more efficient in this case to pass the AA as 
reference.


> `fold` requires function to return something (see 
> [doc](https://dlang.org/phobos/std_algorithm_iteration.html#fold)):
>> for each element x in range, result = fun(result, x) gets 
>> evaluated.
It's clear that the function needs to return something, but I was 
thinking if it would make sense to "document" how one works with 
the accumulator by indicating it as `return` instead of `ref`. I 
just tried to read through: 
https://dlang.org/spec/function.html#param-storage, but there is 
more to it .. like `return ref`, `return ref scope`, and what not 
.. so I am not so sure anymore.




More information about the Digitalmars-d-learn mailing list