首先,一段代码:
λ> let applicationState = ('a','b',(M.fromList $ zip [1..3] [11,22,33],M.fromList $ zip [4,5,6] [44,55,66],M.fromList $ zip [7,8,9] [S.fromList ["77","777","7777"],S.fromList ["88","888","8888"],S.fromList ["99","999","9999"]]))
λ> :t applicationState
applicationState
:: (Char,
Char,
(M.Map Integer Integer,
M.Map Integer Integer,
M.Map Integer (S.Set [Char])))
λ> -- this doesn't work
λ> -- applicationState ^. _3 . _3 . at 9 . contains "9999"
λ> -- this does but only for getting, not for setting
λ> applicationState ^. _3 . _3 . at 9 . to (maybe False (S.member "9999"))
True
#haskell-lens 频道上的友好帮助指示我使用最后一行,但我也希望能够设置。
有什么帮助吗?
稍后编辑:这似乎有效:
λ> applicationState ^. _3 . _3 . at 9 . non S.empty . contains "99999"
False
λ> applicationState & _3 . _3 . at 9 . non S.empty . contains "99999" .~ True