in reply to argmin & argmax

Super useful, now that I've matured in my appreciation for functional list processing thanks to map and grep and List::Util. Stolen and added to my toolkit.

Note that my $val = $block->($_) might as well be my $val = $block->(). The value is still available to the block via $_ because for loops localize with dynamic scope.

Replies are listed 'Best First'.
Re^2: argmin & argmax
by tybalt89 (Monsignor) on May 11, 2025 at 19:21 UTC

    There is also List::UtilsBy::max_by and List::UtilsBy::min_by which do this and have the additional feature of returning several items in list context if they all have the same value.

Re^2: argmin & argmax
by jdporter (Paladin) on May 12, 2025 at 14:43 UTC