mirror of
https://github.com/sigmasternchen/gleam-community-maths
synced 2025-03-15 07:59:01 +00:00
Add explanatory comment for safe assert in combinatorics.list_permutation
This commit is contained in:
parent
52281ce431
commit
d696734400
1 changed files with 2 additions and 0 deletions
|
@ -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] })
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue