Why is there no combination of popFront and front to pop? (aka Python `next`)

Seb via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 16 16:19:09 PST 2016


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!


More information about the Digitalmars-d-learn mailing list