Skip Menu |

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

Report information
The Basics
Id: 86706
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: stefan.majewsky [...] sap.com
Cc:
AdminCc:

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



Subject: wish: shift_all and pop_all
Date: Thu, 4 Jul 2013 13:20:36 +0000
To: "bug-List-MoreUtils [...] rt.cpan.org" <bug-List-MoreUtils [...] rt.cpan.org>
From: "Majewsky, Stefan" <stefan.majewsky [...] sap.com>
I've run across the following pattern in my code: my @target; push @target, shift @source while condition($source[0]); This could be useful as a generic function shift_all(), which removes and returns all leading elements of @source which match the given predicate: @target = shift_all { condition($_) } @source; In a way, this is similar to List::UtilsBy::extract_by(), but it stops at the first non-matching element rather than just skipping non-matches. shift_all() is also similar to List::Util::before as in... @target = before { not condition($_) } @source; But shift_all() changes @source whereas before() does not. And of course, if there's shift_all(), there should be pop_all(), too. Example: my @source = 1..10; @target1 = shift_all { $_ < 4 } @source; # 1..3 @target2 = pop_all { $_ > 7 } @source; # 8..10 # @source is (4..7) now Regards Stefan Majewsky
How will such a function provide additional value over part ?
Subject: Re: [rt.cpan.org #86706] wish: shift_all and pop_all
Date: Tue, 10 Mar 2015 12:39:01 +0000
To: "bug-List-MoreUtils [...] rt.cpan.org" <bug-List-MoreUtils [...] rt.cpan.org>
From: "Majewsky, Stefan" <stefan.majewsky [...] sap.com>
Let's see if RT recognizes replies via mail, since I cannot find my login information right now. Re your remark, you're right; shift_all can be implemented through part. I didn't know about part at the time, or I didn't make the connection. Regards Stefan On 10/03/15 13:04, "Jens Rehsack via RT" <bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
><URL: https://rt.cpan.org/Ticket/Display.html?id=86706 > > >How will such a function provide additional value over part ?
On Tue Mar 10 08:39:26 2015, stefan.majewsky@sap.com wrote: Show quoted text
> Let's see if RT recognizes replies via mail, since I cannot find my login information right now.
I'm pretty sure https://pause.perl.org/pause/query?ACTION=mailpw will help you on this. But for the meantime, mail is fine. Show quoted text
> Re your remark, you're right; shift_all can be implemented through part. I didn't know about part at the time, or I didn't make the connection.
Cool, will close as resolved then ;) Show quoted text
> On 10/03/15 13:04, "Jens Rehsack via RT" <bug-List-MoreUtils@rt.cpan.org> > wrote: >
> ><URL: https://rt.cpan.org/Ticket/Display.html?id=86706 > > > > >How will such a function provide additional value over part ?
Cheers, Jens