Allow for swapping inventory items

This commit is contained in:
2023-02-23 14:12:08 +00:00
parent 6fff71cdcc
commit 683acf8a05
9 changed files with 161 additions and 104 deletions
+10
View File
@@ -15,8 +15,12 @@ module IntMapHelp
unsafeSwapKeys,
safeSwapKeys,
findIndex,
cycleGT,
cycleLT,
) where
import Control.Applicative
import Data.Aeson
import Data.IntMap.Strict
import GHC.Generics
@@ -84,3 +88,9 @@ findIndex t = foldrWithKey f Nothing
f k x _
| t x = Just k
| otherwise = Nothing
cycleGT :: Int -> IntMap a -> Maybe (Int, a)
cycleGT i m = lookupGT i m <|> lookupMin m
cycleLT :: Int -> IntMap a -> Maybe (Int, a)
cycleLT i m = lookupLT i m <|> lookupMax m