std.algorithm sort() and reverse() confusion

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 30 13:11:16 PST 2015


On Friday, January 30, 2015 10:46:54 Ali Çehreli via Digitalmars-d-learn wrote:
> On 01/30/2015 09:55 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
>  > there is no such benefit with reverse, so there's no need to
>  > return anything.
>
> Still, returning the original range would help with chaining calls:
>
>    arr.reverse.map!sqrt

Yes, but arguably, chaining calls in this case is bad, because normally
when you're chaining calls with range-based functions, you're not mutating
the original range, whereas with reverse, you are. So, it could easily give
the impression that it's doing what retro does rather than reversing the
elements in place.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list