www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - No aa.byKey.length?

reply Yuxuan Shui <yshuiv7 gmail.com> writes:
Why?

This is annoying when I need to feed it into a function that 
requires hasLength.
Apr 01 2016
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Apr 01 2016
prev sibling parent reply Ozan <ozan.sueel gmail.com> writes:
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
Apr 02 2016
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
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
Apr 02 2016
parent reply John Colvin <john.loughran.colvin gmail.com> writes:
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)
Apr 03 2016
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
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
Apr 03 2016
parent reply Yuxuan Shui <yshuiv7 gmail.com> writes:
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?
Apr 03 2016
next sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
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
Apr 04 2016
prev sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
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 :)
Apr 04 2016