Allow for stacking of items and combining sensibly
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user