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
Thu Feb 18 05:04:09 PST 2016


On Wednesday, 17 February 2016 at 11:30:40 UTC, Jonathan M Davis 
wrote:
> Feel free to create a pull request to add next. I don't know if 
> it would be accepted or not. I suspect that it mainly comes 
> down to whether such a simple function would be deemed worth 
> adding. On some level, it is a usability improvement, but in 
> theory, we'd prefer to be adding functions to Phobos which add 
> real value rather than simple wrappers that do basic stuff that 
> anyone can easily do. So, it may be accepted as a usability 
> improvement, or it may be rejected on the grounds that it's too 
> simple to be worth it. You won't know if you don't try though.
>
> - Jonathan M Davis

Thanks a lot to you all for your input! It helped me to 
understand D more :)
My use case is really about having `pop{Front,Back}` which 
returns the popped element. I do understand that the current API 
design is a lot more flexible and better [1] and there's no 
objection at all from my side. However on the other side we learn 
the stack syntax with return at university (it's even on 
wikipedia [2]) and thus I am a friend of such a syntax:


auto myFile = ["<crazy header>","1","2"];
// cut off the header
myFile.next.writeln;
// do sth with the body
myFile.map!(to!int).map!"a + 
1".map!(to!string).joiner(",").writeln;


Anyways I will try my best to submit a PR and we can continue to 
discuss pros/cons there - imho it's an excellent learning task :)

[1] 
https://stackoverflow.com/questions/12206242/store-results-of-stdstack-pop-method-into-a-variable
[2] https://en.wikipedia.org/wiki/Stack_(abstract_data_type)


More information about the Digitalmars-d-learn mailing list