Skip to content

Instantly share code, notes, and snippets.

@FCO
Created August 9, 2023 11:00
Show Gist options
  • Save FCO/a8d4bf9710faf7dd0673c56d790bb5de to your computer and use it in GitHub Desktop.
Save FCO/a8d4bf9710faf7dd0673c56d790bb5de to your computer and use it in GitHub Desktop.
Quicksort using classify
multi quicksort([]) { Empty }
multi quicksort([$pivot, *@rest]) {
my %list{Order} is default([]) = @rest.classify: * cmp $pivot;
[ |quicksort(%list{Less}), $pivot, |%list{Same}, |quicksort(%list{More}) ]
}
say quicksort [7, 2, 1, 8, 1, 9, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment