This commit is contained in:
2024-10-01 10:33:15 +01:00
parent 87cbaf911f
commit 8348c1234c
4 changed files with 47 additions and 38 deletions
+9
View File
@@ -18,11 +18,14 @@ module IntMapHelp
cycleGT,
cycleLT,
invertIntMap,
) where
import Control.Applicative
import Data.Aeson
import Data.IntMap.Strict
import qualified Data.Map.Strict as M
import GHC.Generics
import LensHelp
@@ -94,3 +97,9 @@ cycleGT i m = lookupGT i m <|> lookupMin m
cycleLT :: Int -> IntMap a -> Maybe (Int, a)
cycleLT i m = lookupLT i m <|> lookupMax m
invertIntMap :: Ord a => IntMap a -> M.Map a [Int]
invertIntMap = foldrWithKey
(\k xs -> M.insertWith (++) xs [k])
mempty