Skip to content

Commit 115fe68

Browse files
committed
chore: deprecate list:permutations and list:permutationsWithReplacement in favor of list:combinations and list:combinationsWithReplacement
1 parent ec8bbb7 commit 115fe68

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

List.ark

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,14 +839,14 @@
839839
# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early
840840
# =begin
841841
# (let data [0 1 2 3])
842-
# (list:permutations data 3 (fun (perm) (print perm)))
842+
# (list:combinations data 3 (fun (perm) (print perm)))
843843
# # [0 1 2]
844844
# # [0 1 3]
845845
# # [0 2 3]
846846
# # [1 2 3]
847847
# =end
848848
# @author https://github.com/SuperFola
849-
(let permutations (fun ((ref _L) _r _f) {
849+
(let combinations (fun ((ref _L) _r _f) {
850850
(let _len (len _L))
851851
(if (and (<= _r _len) (> _r 0))
852852
{
@@ -873,14 +873,31 @@
873873
(set _continue false)) }
874874
(set _continue false)) }) }) }) }))
875875

876+
# @brief Compute permutations of length _r from a given list
877+
# @details The original list is not modified.
878+
# @param _L list to get values from
879+
# @param _r number of elements per permutation
880+
# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early
881+
# @deprecated Use list:combinations. Will be removed in ArkScript 4.5.0
882+
# =begin
883+
# (let data [0 1 2 3])
884+
# (list:permutations data 3 (fun (perm) (print perm)))
885+
# # [0 1 2]
886+
# # [0 1 3]
887+
# # [0 2 3]
888+
# # [1 2 3]
889+
# =end
890+
# @author https://github.com/SuperFola
891+
(let permutations combinations)
892+
876893
# @brief Compute permutations of length _r from a given list, allowing individual elements to be repeated more than once
877894
# @details The original list is not modified.
878895
# @param _L list to get values from
879896
# @param _r number of elements per permutation
880897
# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early
881898
# =begin
882899
# (let data [0 1 2])
883-
# (list:permutationsWithReplacement data 2 (fun (perm) (print perm)))
900+
# (list:combinationsWithReplacement data 2 (fun (perm) (print perm)))
884901
# # [0 0]
885902
# # [0 1]
886903
# # [0 2]
@@ -889,7 +906,7 @@
889906
# # [2 2]
890907
# =end
891908
# @author https://github.com/SuperFola
892-
(let permutationsWithReplacement (fun ((ref _L) _r _f) {
909+
(let combinationsWithReplacement (fun ((ref _L) _r _f) {
893910
(let _len (len _L))
894911
(if (and (!= 0 _len) (> _r 0))
895912
{
@@ -915,3 +932,22 @@
915932
(if (= stopIteration (_f (select _L _indices)))
916933
(set _continue false)) }
917934
(set _continue false)) }) }) }) }))
935+
936+
# @brief Compute permutations of length _r from a given list, allowing individual elements to be repeated more than once
937+
# @details The original list is not modified.
938+
# @param _L list to get values from
939+
# @param _r number of elements per permutation
940+
# @param _f function to call on each permutation. It can return list:stopIteration to stop iteration early
941+
# @deprecated Use list:combinationsWithReplacement. Will be removed in ArkScript 4.5.0
942+
# =begin
943+
# (let data [0 1 2])
944+
# (list:permutationsWithReplacement data 2 (fun (perm) (print perm)))
945+
# # [0 0]
946+
# # [0 1]
947+
# # [0 2]
948+
# # [1 1]
949+
# # [1 2]
950+
# # [2 2]
951+
# =end
952+
# @author https://github.com/SuperFola
953+
(let permutationsWithReplacement combinationsWithReplacement)

0 commit comments

Comments
 (0)