Skip to content

Instantly share code, notes, and snippets.

@librasteve
Created February 2, 2024 11:22
Show Gist options
  • Save librasteve/5467a52a91802e3932ed584ac9e666b1 to your computer and use it in GitHub Desktop.
Save librasteve/5467a52a91802e3932ed584ac9e666b1 to your computer and use it in GitHub Desktop.
GroupBy Test
say my @input = (1, 4, -3, -6, 5, 6);
sub demerge( $aoa is rw, $value ) {
state $first = 1;
state $newi = 0;
state $last;
my $this = $value.sign;
if $first {
$first = 0
} elsif $this != $last {
$newi++
}
$aoa[$newi].push: $value;
$last = $this;
}
my $aoa;
@input.map({demerge($aoa, $_)});
say $aoa.map(*.max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment