Allow for stacking of items and combining sensibly

This commit is contained in:
2021-12-03 17:18:06 +00:00
parent b2a9192fe4
commit b41e3e3637
24 changed files with 166 additions and 159 deletions
+11
View File
@@ -4,6 +4,7 @@ module IntMapHelp
, insertNewKey
, insertWithNewKeys
, swapKeys
, findIndex
)
where
--import Data.List hiding (foldr,insert)
@@ -23,3 +24,13 @@ insertWithNewKeys xs m = union m $ fromList $ zip [newKey m..] xs
{- | Swaps two keys. Unsafe: assumes both keys exist. -}
swapKeys :: Int -> Int -> IntMap a -> IntMap a
swapKeys i j m = insert i (m ! j) $ insert j (m ! i) m
-- ideally this should short circuit, I am not sure whether it does or not
-- though
findIndex :: (a -> Bool) -> IntMap a -> Maybe Int
findIndex t = foldrWithKey f Nothing
where
f _ _ (Just k) = Just k
f k x _
| t x = Just k
| otherwise = Nothing