Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: jo [...] sommrey.de
Cc:
AdminCc:

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



Subject: documentation issue with reduce_u
Date: Sun, 05 Jul 2020 08:30:54 +0000
To: bug-List-MoreUtils [...] rt.cpan.org
From: Jörg Sommrey <jo [...] sommrey.de>
There is an issue with the documentation of reduce_u: reduce_u BLOCK LIST Reduce LIST by calling BLOCK in scalar context for each element of LIST. $a contains the progressional result and is initialized with 1. $b contains the current processed element of LIST and $_ contains the index of the element in $b. This function has been added if one might need the extra of the index value but need an individual initialization. This is contradictory: "is initialized with 1" vs. "if one [...] need an individual initialization" and does not describe the actual behaviour. Furthermore, the usage of this function is not as convenient as it could be. An example with List::Util:reduce and List::MoreUtils::reduce_u: $s1 = do {my $i = 0; reduce {$a . substr $b, $i++, 1} '', qw(abc 123 xyz)}; $s2 = reduce_u {($a // '') . substr $b, $_, 1} qw(abc 123 xyz); Both need an extra effort to get an individual identity AND indexing. My expectation for reduce_u was like this: sub reduce_i (&@) { my $code = shift; my $i = 0; local $_; reduce {$_ = $i++; $code->()} @_; } $s3 = reduce_i {$a . substr $b, $_, 1} '', qw(abc 123 xyz); This would fit into the _u family of functions as it returns undef when called with less than 2 elements. Best regards, -jo
On Sun Jul 05 04:38:47 2020, jo@sommrey.de wrote: Show quoted text
> There is an issue with the documentation of reduce_u: > > reduce_u BLOCK LIST > Reduce LIST by calling BLOCK in scalar context for each element of > LIST. > $a contains the progressional result and is initialized with 1.
Correct - the text should have be changed into "is uninitialized." Maybe that's already fixed in HEAD... $b Show quoted text
> contains the current processed element of LIST and $_ contains the > index > of the element in $b. > > This function has been added if one might need the extra of the index > value but need an individual initialization. > > This is contradictory: "is initialized with 1" vs. "if one [...] need > an individual initialization" > and does not describe the actual behaviour. > > Furthermore, the usage of this function is not as convenient as it > could be. An > example with List::Util:reduce and List::MoreUtils::reduce_u: > > $s1 = do {my $i = 0; reduce {$a . substr $b, $i++, 1} '', qw(abc 123 > xyz)}; > $s2 = reduce_u {($a // '') . substr $b, $_, 1} qw(abc 123 xyz);
This is intensional. It's misuse to rely on List::MoreUtils::reduce_u for that. The intention of using is for some extremely rare algorithms which can't be reasonably initialized with a "dumb" default value. Show quoted text
> Both need an extra effort to get an individual identity AND indexing. > My expectation for > reduce_u was like this: > > sub reduce_i (&@) { > my $code = shift; > my $i = 0; > local $_; > reduce {$_ = $i++; $code->()} @_; > } > $s3 = reduce_i {$a . substr $b, $_, 1} '', qw(abc 123 xyz);
That's something complete different and far away from the intension of reduce_u. Show quoted text
> This would fit into the _u family of functions as it returns undef > when called with less than 2 elements.
Cheers, Jens
Documentation is fixed and included in recent uploaded 0.429_001