replaceFirst, findPieces, and takeExactly

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jan 22 20:30:53 PST 2011


On 01/22/2011 10:16 PM, spir wrote:
> On 01/22/2011 10:27 PM, Andrei Alexandrescu wrote:
>> The first abstraction is the takeExactly() function:
>>
>> http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly
>>
>>
>>
>> That function allows you to pick a determined number of elements from a
>> range, assuming the range is never shorter than that. That sounds a bit
>> obscure, but plays a pivotal role in findParts() (which is the name I
>> settled on for the equivalent of Python's partition()):
>
> What is reasoning behind having length set on takeExactly's result
> (while if succeeds, you know it, or don't you?), and not on take's
> result (which can return a smaller number of elements)? I would expect
> the opposite, or both, but maybe it's only me?
>
> Denis

If the ranges involved are forward ranges, not passing around length 
information essentially throws away information painstakingly acquired 
(by means of O(n)).

Andrei


More information about the Digitalmars-d mailing list