
4 Feb
2007
4 Feb
'07
2:25 p.m.
J. Garrett Morris wrote:
Maybe has a Monad instance, so you can write this as follows (untested):
exists str wmap = boolFromMaybe exists' where exists' = do x <- Map.lookup (sort str) wmap find (== str) (snd x) boolFromMaybe (Just _) = True boolFromMaybe Nothing = False
Small improvement (Data.Maybe is underappreciated):
exists str wmap = isJust exists' where exists' = do x <- Map.lookup (sort str) wmap find (== str) (snd x)
and maybe another improvement, though this is dependent on your tastes:
exists s wmap = isJust $ Map.lookup (sort s) wmap >>= find (== s) . snd
-Udo -- Catproof is an oxymoron, childproof nearly so.