X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhtsn-import.git;a=blobdiff_plain;f=src%2FMisc.hs;fp=src%2FMisc.hs;h=cb992c78c7ade99443c2076b35d777247414b9a0;hp=0000000000000000000000000000000000000000;hb=fdd85d5ed7944e6a6373c99c2e341f370cd931f8;hpb=073bbfba4165d4c01d29daaa7523c35c6cc7d114 diff --git a/src/Misc.hs b/src/Misc.hs new file mode 100644 index 0000000..cb992c7 --- /dev/null +++ b/src/Misc.hs @@ -0,0 +1,24 @@ +-- | 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