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.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to