Why is there no combination of popFront and front to pop? (aka Python `next`)
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 16 17:45:24 PST 2016
On 17/02/16 1:19 PM, Seb wrote:
> I am still in the process of learning D - it's a fantastic language.
> Thanks so much!
> However there is one thing that I came by which I think is a bit
> annoying and could be easily solved - there seems to be no way to
> combine `front` and `popFront` in one call even tough this use case
> seems quite frequently to me.
> At least I am used from Python to use next(<some lazy loaded stream>) to
> get its next element and I desperately searched for similar method in D.
>
> I know that I can use `.front` and `popFront`, but why isn't there `pop`
> or `next` that returns the first element from the lazy loaded range? I
> know there is `takeOne` (which doesn't modify the source) and `dropOne`
> (which will return the resulting array after dropping one element).
>
> In any case such a next method would be very easy to implement (see
> below) and thus I am wondering why it isn't part of phobos?
>
> ```
> auto next(Range)(ref Range a){
> auto b = a.front;
> a.popFront();
> return b;
> }
>
> ````
>
> Thanks for your input!
Oh but there is:
http://dlang.org/phobos/std_range_primitives.html#.moveFront
More information about the Digitalmars-d-learn
mailing list