toml-reader-0.2.0.0: TOML format parser compliant with v1.0.0.
Safe HaskellSafe-Inferred
LanguageHaskell2010

TOML.Utils.Map

Synopsis

Documentation

getPathLens Source #

Arguments

:: (Monad m, Ord k) 
=> (NonEmpty k -> Maybe v -> m (Map k v, Map k v -> v))

How to get and set the next Map from the possibly missing value. Passes in the path taken so far.

-> NonEmpty k 
-> Map k v 
-> m (Maybe v, v -> Map k v) 

For a non-empty list of keys, iterate through the given Map and return the possibly missing value at the path and a function to set the value at the given path and return the modified input Map.

let obj = undefined -- { "a": { "b": { "c": 1 } } }
(mValue, setValue) <- getPathLens doRecurse ["a", "b", "c"] obj

print mValue -- Just 1
print (setValue 2) -- { "a": { "b": { "c": 2 } } }

getPath :: (Monad m, Ord k) => (NonEmpty k -> Maybe v -> m (Map k v)) -> NonEmpty k -> Map k v -> m (Maybe v) Source #

Same as getPathLens, except without the setter.