Tweak inventory management

This commit is contained in:
2021-12-01 01:55:20 +00:00
parent 0ed260c9b7
commit b9e4a80a46
12 changed files with 138 additions and 109 deletions
+4
View File
@@ -2,6 +2,7 @@ module ListHelp
(module Data.List
,initOrNull
, insertOver
, swapIndices
)where
import Data.List
@@ -11,3 +12,6 @@ initOrNull xs = init xs
insertOver :: Int -> a -> [a] -> [a]
insertOver i x xs = take i xs ++ x : drop (i+1) xs
swapIndices :: Int -> Int -> [a] -> [a]
swapIndices i j xs = insertOver i (xs !! j) . insertOver j (xs !! i) $ xs