-- | Miscellaneous utility functions
module Misc (
double_just )
where
-- | If given 'Nothing', return 'Nothing'. Otherwise wrap our argument
-- in another 'Just'. This is used when handling optional XML
-- elements that are optionally empty. If the element is missing, we
-- want 'Nothing'. And if the contents are missing, we want
-- 'Nothing' then too. But if something is present, we need @Just
-- (Just foo)@ for the types to match up.
--
-- ==== __Examples__:
--
-- >>> double_just Nothing
-- Nothing
-- >>> double_just (Just 2)
-- Just (Just 2)
--
double_just :: (Maybe a) -> Maybe (Maybe a)
double_just val =
case val of
Nothing -> Nothing
just_something -> Just just_something