Created
April 17, 2012 01:18
-
-
Save yihuang/2402737 to your computer and use it in GitHub Desktop.
adjust nested data structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test where | |
import qualified Data.Vector as V | |
import qualified Data.HashMap.Strict as M | |
import Data.Hashable (Hashable) | |
type MyData k v = V.Vector (M.HashMap k v) | |
adjustVec :: Int -> (a -> a) -> V.Vector a -> V.Vector a | |
adjustVec ix f vec = | |
let v = vec V.! ix | |
in vec V.// [(ix, f v)] | |
modify :: (Eq k, Hashable k) => Int -> k -> v -> MyData k v -> MyData k v | |
modify idx k v = adjustVec idx (M.insert k v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment