Skip Menu |
 

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 103250
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 1.44



Subject: feature request: List::Util::uniq
Download (untitled) / with headers
text/plain 114b
uniq is the main thing from LMU that I regularly use, that hasn't yet been ported to LU. Is it possible to add it?
Download (untitled) / with headers
text/plain 463b
On Wed Apr 01 13:41:19 2015, ETHER wrote: Show quoted text
> uniq is the main thing from LMU that I regularly use, that hasn't yet > been ported to LU. Is it possible to add it?
Specification, mostly. I'm not sure I like the idea of a single "uniq" function that doesn't clearly specify whether it performs stringy or numerical, or even referential identity comparisons to reduce equivalent members. uniq 123, "123.0" should return a one or two-element list? -- Paul Evans
Download (untitled) / with headers
text/plain 820b
On 2015-04-01 10:55:50, PEVANS wrote: Show quoted text
> On Wed Apr 01 13:41:19 2015, ETHER wrote:
> > uniq is the main thing from LMU that I regularly use, that hasn't yet > > been ported to LU. Is it possible to add it?
> > Specification, mostly. > > I'm not sure I like the idea of a single "uniq" function that doesn't > clearly specify whether it performs stringy or numerical, or even > referential identity comparisons to reduce equivalent members. > > uniq 123, "123.0" > > should return a one or two-element list?
What about an optional first parameter which is a coderef that does the equality check? e.g. uniq { $a cmp $b } 123, "123.0" # returns two elements uniq { $a <=> $b } 123, "123.0" # returns one element uniq 123, "123.0" # does what LMU does (stringy comparison, I think)

LMU states it uses hash-keys as its method for uniq.

And that implies that its stringy-uniqueness.

I would vote in favour of

 

uniq :  in terms of cmp

nuniq: in terms of <=>

 

For any more complex cases, UtilsBy should be suitable =)

Download (untitled) / with headers
text/plain 1.1k
On 2015-04-01 14:36:34, ETHER wrote: Show quoted text
> On 2015-04-01 10:55:50, PEVANS wrote:
> > On Wed Apr 01 13:41:19 2015, ETHER wrote:
> > > uniq is the main thing from LMU that I regularly use, that hasn't > > > yet > > > been ported to LU. Is it possible to add it?
> > > > Specification, mostly. > > > > I'm not sure I like the idea of a single "uniq" function that doesn't > > clearly specify whether it performs stringy or numerical, or even > > referential identity comparisons to reduce equivalent members. > > > > uniq 123, "123.0" > > > > should return a one or two-element list?
> > > What about an optional first parameter which is a coderef that does > the equality check? e.g. > > uniq { $a cmp $b } 123, "123.0" # returns two elements > uniq { $a <=> $b } 123, "123.0" # returns one element > uniq 123, "123.0" # does what LMU does (stringy > comparison, I think)
I also thought about this, but this would make that the obvious implementation (using a seen-hash) impossible... maybe better would be a normalization function which is used for the seen-hash value: uniq { $_ } 123, "123.0" # returns two elements uniq { $_+0 } 123, "123.0" # returns one element (probably the first)
Download (untitled) / with headers
text/plain 821b
On Wed Apr 01 14:36:34 2015, ETHER wrote: Show quoted text
> > I'm not sure I like the idea of a single "uniq" function that doesn't > > clearly specify whether it performs stringy or numerical, or even > > referential identity comparisons to reduce equivalent members. > > > > uniq 123, "123.0" > > > > should return a one or two-element list?
Given the rest of perl, I think stringy comparison is the non-surprising choice. Show quoted text
> What about an optional first parameter which is a coderef that does > the equality check? e.g. > > uniq { $a cmp $b } 123, "123.0" # returns two elements > uniq { $a <=> $b } 123, "123.0" # returns one element > uniq 123, "123.0" # does what LMU does (stringy > comparison, I think)
That sounds way to complicated and potentially surprising (if the list contains a coderef). Leon
Download (untitled) / with headers
text/plain 468b
On Wed Apr 01 14:36:34 2015, ETHER wrote: Show quoted text
> What about an optional first parameter which is a coderef that does > the equality check? e.g. > > uniq { $a cmp $b } 123, "123.0" # returns two elements > uniq { $a <=> $b } 123, "123.0" # returns one element > uniq 123, "123.0" # does what LMU does (stringy > comparison, I think)
I don't believe it's possible to do optional code blocks with any kind of prototype. sort cheats. -- Paul Evans
Download (untitled) / with headers
text/plain 517b
On Wed Apr 01 18:06:49 2015, SREZIC wrote: Show quoted text
> I also thought about this, but this would make that the obvious > implementation (using a seen-hash) impossible... maybe better would be > a normalization function which is used for the seen-hash value: > > uniq { $_ } 123, "123.0" # returns two elements > uniq { $_+0 } 123, "123.0" # returns one element (probably the first)
That's exactly what List::UtilsBy::uniq_by already does: https://metacpan.org/pod/List::UtilsBy#vals-uniq_by-KEYFUNC-vals -- Paul Evans
Download (untitled) / with headers
text/plain 390b
On Wed Apr 01 15:11:22 2015, KENTNL wrote: Show quoted text
> LMU states it uses hash-keys as its method for uniq. > > And that implies that its stringy-uniqueness. > > I would vote in favour of > > uniq : in terms of cmp > > nuniq: in terms of <=> > > For any more complex cases, UtilsBy should be suitable =)
This doesn't seem unreasonable in fact. Perhaps I'll just go with this... -- Paul Evans
Download (untitled) / with headers
text/plain 473b
On 2015-04-01 15:36:40, PEVANS wrote: Show quoted text
> On Wed Apr 01 15:11:22 2015, KENTNL wrote:
> > LMU states it uses hash-keys as its method for uniq. > > And that implies that its stringy-uniqueness. > > I would vote in favour of > > > > uniq : in terms of cmp > > nuniq: in terms of <=> > > > > For any more complex cases, UtilsBy should be suitable =)
> > This doesn't seem unreasonable in fact. Perhaps I'll just go with this...
+1 (thanks for the bikeshedding, everyone!) :D
Download (untitled) / with headers
text/plain 250b
Actually given the idea of "maxstr" I'm feeling more like uniq uniqnum is the way to go. Anyway, unlikely to have time to write this in the next couple of weeks... If anyone else feels like it I could take a look at patches... -- Paul Evans
Download (untitled) / with headers
text/plain 219b
I've now started this at https://github.com/Scalar-List-Utils/Scalar-List-Utils/tree/uniq Has docs and (some minimal) tests, but as yet no XS implementation. Using a trivially-simple PP one for now. -- Paul Evans
Now implemented and released in 1.44 -- Paul Evans


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.