Skip to content

Commit

Permalink
Add explanatory comment for safe assert in combinatorics.list_permuta…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
DanielSherlock committed Nov 19, 2023
1 parent 52281ce commit d696734
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gleam_community/maths/combinatorics.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ pub fn list_permutation(arr: List(a)) -> List(List(a)) {
[] -> [[]]
_ -> {
use x <- list.flat_map(arr)
// `x` is drawn from the list `arr` above,
// so Ok(...) can be safely asserted as the result of `list.pop` below
let assert Ok(#(_, remaining)) = list.pop(arr, fn(y) { x == y })
list.map(list_permutation(remaining), fn(perm) { [x, ..perm] })
}
Expand Down

0 comments on commit d696734

Please sign in to comment.