3 ms·
I rather like that, `if condition` is a 0/1 iteration with no input. flatMap can return empty, what should map return when run on false, None?
by karmakaze 7y ago
I rather like that, `if condition` is a 0/1 iteration with no input. flatMap can return empty, what should map return when run on false, None?
- mrgriffin 7y agoI'd probably think of Bool as being isomorphic to Maybe (), which would mean your map implementation looks a bit like: map :: Bool -> (() -> b) -> Maybe b map True f = Just (f ()) map False _ = Nothing Or, in Haskell because you've got laziness you could go with: map :: Bool -> b -> Maybe b Which already exists as a combination of Control.Monad.guard and Data.Functor.(<$). map tf b = b <$ guard tf