Skip Menu |
 

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

Report information
The Basics
Id: 89539
Status: rejected
Worked: 15 min
Priority: 0/
Queue: List-MoreUtils

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

Bug Information
Severity: Wishlist
Broken in:
  • 0.04
  • 0.05
  • 0.06
  • 0.07
  • 0.08
  • 0.09
  • 0.10
  • 0.11
  • 0.12
  • 0.13
  • 0.14
  • 0.15
  • 0.16
  • 0.17
  • 0.18
  • 0.19
  • 0.20
  • 0.21
  • 0.22
  • 0.23
  • 0.23_01
  • 0.24
  • 0.25_01
  • 0.25_02
  • 0.26
  • 0.27_01
  • 0.27_02
  • 0.27_03
  • 0.27_04
  • 0.28
  • 0.29
  • 0.30
  • 0.31_01
  • 0.31_02
  • 0.32
  • 0.33
  • 0.33_005
  • 0.33_007
  • 0.400_001
Fixed in: (no value)



Subject: running_unique list utility function
Download (untitled) / with headers
text/plain 1.2k
I could not find a running unique function anywhere on the net. And this little sub took quite a long time to get all of the edge cases perfected. If you would like, please add it to the List::MoreUtils package. If not I may add it to the List:: namespace separately. Thanks, Mike returns (undef,4,1,2,undef,2,3,undef,,3,2,1,3,1,4,undef) perl -e ' #Copyright (c) 2013 Michael R. Davis #License: This library is free software; you can redistribute #it and/or modify it under the same terms as Perl itself. use strict; use warnings; my @list=running_unique( undef,undef,4,1,1,1,2, undef,undef,2,2,3,3,undef,"","","", 3,2,2,1,1,3,1,1,1,4,undef,undef); print join(",", map {defined($_) ? $_ : "undef"} @list), "\n"; sub running_unique { my $prev=not($_[0]); #very smart initial value my @list=grep { my $keep=0; my $this=$_; if (defined($prev) and defined($this)) { $keep=1 if $prev ne $this; #string compare! } else { $keep=1 unless (!defined($prev) and !defined($this)); } $prev=$this; $keep } @_; wantarray ? @list : \@list; } ' mrdvt92
Download (untitled) / with headers
text/plain 590b
I'm sorry - but that doesn't compute. 1) List::MoreUtils is for collecting utils operating on lists which are neither part of Perl itself (as grep is) and not in List::Util. 2) You're implementation lacks on comparing numbers (see Scalar::Util::looks_like_number) I currently admit that a collection of typically used filter functions would be nice, to allow use List::FilterFuncs; my $filter = List::FilterFuncs->no_repetition; my @no_repetitions = grep { $filter->($_); } @my_list; Maybe a similar thing could be done for Hash::MoreUtils (I received similar requests there ...) Jens
Download (untitled) / with headers
text/plain 869b
On Wed Oct 16 02:24:32 2013, REHSACK wrote: Show quoted text
> I currently admit that a collection of typically used filter functions > would be nice, to allow > > use List::FilterFuncs; > my $filter = List::FilterFuncs->no_repetition; > my @no_repetitions = grep { $filter->($_); } @my_list; >
I think you are correct this is really a grep capability. I think an object based API would be more capable than an anonymous subroutine API. my $f=List::Grep::Functions->new(type=>"repetition_filter_string"); my $f=List::Grep::Functions->repetition_filter_string if $maybe; my @input=qw{[1,2], [1,2], [2,2]}; my @list=grep ($f->analyze(join("-", @$_))) @input; It also has the flexibility to handle digging into the data to build the "key" as well. Do you have any other candidates for a package? I hacked my project away so there is no immediate motivation. Thanks, Mike mrdvt92
RT-Send-CC: leonerd [...] leonerd.org.uk
The longer I think about it, the longer I think that should belong to List::UtilsBy.
Download (untitled) / with headers
text/plain 378b
On Wed Mar 19 04:11:01 2014, REHSACK wrote: Show quoted text
> The longer I think about it, the longer I think that should belong to > List::UtilsBy.
I'm not sure I agree. The point of List::UtilsBy is that it provides functional operators; that is, functions that take a function themselves. There's no function here in the running_unique, so it doesn't seem like a good fit. -- 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.