From d6967344008183c98917990a2f0d15e577776d3b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 19 Nov 2023 22:59:03 +0000 Subject: [PATCH] Add explanatory comment for safe assert in combinatorics.list_permutation --- src/gleam_community/maths/combinatorics.gleam | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gleam_community/maths/combinatorics.gleam b/src/gleam_community/maths/combinatorics.gleam index d65bbab..ee771a1 100644 --- a/src/gleam_community/maths/combinatorics.gleam +++ b/src/gleam_community/maths/combinatorics.gleam @@ -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] }) }