]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/Misc.hs
Fix present-but-empty vleague parsing in jfilexml.
[dead/htsn-import.git] / src / Misc.hs
1 -- | Miscellaneous utility functions
2 module Misc (
3 double_just )
4 where
5
6 -- | If given 'Nothing', return 'Nothing'. Otherwise wrap our argument
7 -- in another 'Just'. This is used when handling optional XML
8 -- elements that are optionally empty. If the element is missing, we
9 -- want 'Nothing'. And if the contents are missing, we want
10 -- 'Nothing' then too. But if something is present, we need @Just
11 -- (Just foo)@ for the types to match up.
12 --
13 -- ==== __Examples__:
14 --
15 -- >>> double_just Nothing
16 -- Nothing
17 -- >>> double_just (Just 2)
18 -- Just (Just 2)
19 --
20 double_just :: (Maybe a) -> Maybe (Maybe a)
21 double_just val =
22 case val of
23 Nothing -> Nothing
24 just_something -> Just just_something