3

如何使用镜头语法检查地图是否有键?

import qualified Map as Map

let x = Map.member "bla" m

如何用镜头写这个?

4

2 回答 2

4

使用has.

M.fromList [("bla", ())] & has (ix "bla")
于 2014-02-27T21:33:04.483 回答
1

使用Contains实例。

>>> Map.fromList [("bla", ())] ^. contains "bla"
True

>>> Map.fromList [("bla", ())] & contains "bla" .~ False
Map.fromList []
于 2014-02-27T20:41:56.050 回答