Vagif Verdi
Vagif Verdi

Reputation: 4896

How to check if map has a key using lens syntax?

How to check if map has a key using lens syntax?

import qualified Map as Map

let x = Map.member "bla" m

How to write this using lenses?

Upvotes: 4

Views: 660

Answers (2)

Anthony
Anthony

Reputation: 3791

Use has.

M.fromList [("bla", ())] & has (ix "bla")

Upvotes: 5

J. Abrahamson
J. Abrahamson

Reputation: 74344

Use the Contains instance.

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

>>> Map.fromList [("bla", ())] & contains "bla" .~ False
Map.fromList []

Upvotes: 1

Related Questions