]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/Misc.hs
Fix present-but-empty vleague parsing in jfilexml.
[dead/htsn-import.git] / src / Misc.hs
diff --git a/src/Misc.hs b/src/Misc.hs
new file mode 100644 (file)
index 0000000..cb992c7
--- /dev/null
@@ -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