Gotcha with photos' documentation

H. S. Teoh hsteoh at qfbox.info
Fri Dec 9 01:21:52 UTC 2022


On Thu, Dec 08, 2022 at 09:15:45PM +0100, Christian Köstlin via Digitalmars-d-learn wrote:
> Recently I stumbled upon a small issue in dlang's docs.
> I wanted to look up uniq in std.algorithm. Started from
> https://dlang.org/phobos/std_algorithm.html and clicked uniq, no
> problem, all good. But my code did not work. After some debugging
> I saw, that for some inputs uniq just did not work. I clicked around
> some more in the online docs and finally arrived at https://dlang.org
> /phobos/std_algorithm_iteration.html which also lists uniq at the
> beginning of the page and mentions (only there) that the input needs to
> be sorted.
> With that all was back to good :)
> 
> Would it make sense to mention this prerequisite also at the main
> documentation of uniq
> (https://dlang.org/phobos/std_algorithm_iteration.html#uniq)
[...]

Technically, .uniq can be used with a custom predicate for collapsing
adjacent equivalent items, which can be useful on non-sorted ranges
sometimes.

OTOH, it's true that the most common use case for .uniq is on sorted
ranges.  The docs do say that it iterates "unique *consecutive*
elements" (emphasis mine), but I guess this is easy to miss.  I'll see
if I can reword this to be more explicit.


T

-- 
Spaghetti code may be tangly, but lasagna code is just cheesy.


More information about the Digitalmars-d-learn mailing list