No aa.byKey.length?
Why? This is annoying when I need to feed it into a function that requires hasLength.
Re: No aa.byKey.length?
On 04/01/2016 01:50 PM, Yuxuan Shui wrote: Why? This is annoying when I need to feed it into a function that requires hasLength. Sounds easy to implement. Please file an enhancement request: https://issues.dlang.org/ Ali
Re: No aa.byKey.length?
On Friday, 1 April 2016 at 20:50:32 UTC, Yuxuan Shui wrote: Why? This is annoying when I need to feed it into a function that requires hasLength. aa.keys.length
Re: No aa.byKey.length?
On Saturday, April 02, 2016 15:38:30 Ozan via Digitalmars-d-learn wrote: > On Friday, 1 April 2016 at 20:50:32 UTC, Yuxuan Shui wrote: > > Why? > > > > This is annoying when I need to feed it into a function that > > requires hasLength. > > aa.keys.length That allocates an array. Doing that would be like doing aa.byKeys().array().length. And associate arrays already have length. You can do auto len = aa.length; The problem is when you want to operate on a range, and the function that you want to pass it to wants length on the range. If byKeys returned a range with length, then that would work, but since it doesn't, it doesn't. Having other ways to get the length doesn't help. - Jonathan M Davis
Re: No aa.byKey.length?
On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote: On Saturday, April 02, 2016 15:38:30 Ozan via Digitalmars-d-learn wrote: On Friday, 1 April 2016 at 20:50:32 UTC, Yuxuan Shui wrote: > Why? > > This is annoying when I need to feed it into a function that > requires hasLength. aa.keys.length That allocates an array. Doing that would be like doing aa.byKeys().array().length. And associate arrays already have length. You can do auto len = aa.length; The problem is when you want to operate on a range, and the function that you want to pass it to wants length on the range. If byKeys returned a range with length, then that would work, but since it doesn't, it doesn't. Having other ways to get the length doesn't help. - Jonathan M Davis Maybe aa.byKey().takeExactly(aa.length)
Re: No aa.byKey.length?
On Sunday, April 03, 2016 23:46:10 John Colvin via Digitalmars-d-learn wrote: > On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote: > > On Saturday, April 02, 2016 15:38:30 Ozan via > > > > Digitalmars-d-learn wrote: > >> On Friday, 1 April 2016 at 20:50:32 UTC, Yuxuan Shui wrote: > >> > Why? > >> > > >> > This is annoying when I need to feed it into a function that > >> > requires hasLength. > >> > >> aa.keys.length > > > > That allocates an array. Doing that would be like doing > > aa.byKeys().array().length. And associate arrays already have > > length. You > > can do > > > > auto len = aa.length; > > > > The problem is when you want to operate on a range, and the > > function that you want to pass it to wants length on the range. > > If byKeys returned a range with length, then that would work, > > but since it doesn't, it doesn't. Having other ways to get the > > length doesn't help. > > Maybe > > aa.byKey().takeExactly(aa.length) Yeah, that's a clever workaround. - Jonathan M Davis
Re: No aa.byKey.length?
On Monday, 4 April 2016 at 00:50:27 UTC, Jonathan M Davis wrote: On Sunday, April 03, 2016 23:46:10 John Colvin via Digitalmars-d-learn wrote: On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote: > [...] Maybe aa.byKey().takeExactly(aa.length) Yeah, that's a clever workaround. - Jonathan M Davis So should we not add length to byKey?
Re: No aa.byKey.length?
On Monday, April 04, 2016 02:32:56 Yuxuan Shui via Digitalmars-d-learn wrote: > On Monday, 4 April 2016 at 00:50:27 UTC, Jonathan M Davis wrote: > > On Sunday, April 03, 2016 23:46:10 John Colvin via > > > > Digitalmars-d-learn wrote: > >> On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis > >> > >> wrote: > >> > [...] > >> > >> Maybe > >> > >> aa.byKey().takeExactly(aa.length) > > > > Yeah, that's a clever workaround. > > So should we not add length to byKey? I don't see any reason for the result of byKey to not have length. It's just that given that it doesn't currently have length, John's suggestion provides a way to turn it into a range with length. - Jonathan M Davis
Re: No aa.byKey.length?
On Monday, 4 April 2016 at 02:32:56 UTC, Yuxuan Shui wrote: On Monday, 4 April 2016 at 00:50:27 UTC, Jonathan M Davis wrote: On Sunday, April 03, 2016 23:46:10 John Colvin via Digitalmars-d-learn wrote: On Saturday, 2 April 2016 at 16:00:51 UTC, Jonathan M Davis wrote: > [...] Maybe aa.byKey().takeExactly(aa.length) Yeah, that's a clever workaround. - Jonathan M Davis So should we not add length to byKey? Yes. But until that happens, my workaround allows you to carry on getting work done :)