+-- | Choose a nonempty monoid from our two arguments, preferring the
+-- second. So if the second monoid is non-'mempty', we'll return
+-- that. Otherwise the first.
+--
+-- ==== _Examples_
+--
+-- The second list is preferred if both are nonempty:
+--
+-- >>> merge_monoid [1,2] [3,4]
+-- [3,4]
+--
+-- However, if the second list is empty, the first is returned:
+--
+-- >>> merge_monoid [1,2] []
+-- [1,2]
+--
+-- And if both are empty, we return the first (i.e. empty) list:
+--
+-- >>> merge_monoid [] []
+-- []
+--
+merge_monoid :: (Eq a, Monoid a) => a -> a -> a
+merge_monoid l1 l2 = if l2 == mempty then l1 else l2
+
+
+-- | Like 'merge_monoid', except for optional things. We take two
+-- (potentially 'Nothing') values, and then try to choose a
+-- non-'Nothing' one, preferring the second argument.
+--
+-- ==== _Examples_
+--
+-- The second is preferred if it is non-'Nothing':
+--
+-- >>> merge_maybes (Just 3) (Just 4)
+-- Just 4
+--
+-- >>> merge_maybes Nothing (Just 4)
+-- Just 4
+--
+-- However, if the second argument is 'Nothing', the first is
+-- returned:
+--
+-- >>> merge_maybes (Just 1) Nothing
+-- Just 1
+--
+-- If both are 'Nothing', we return 'Nothing':
+--
+-- >>> merge_maybes Nothing Nothing
+-- Nothing
+--
+merge_maybes :: (Maybe a) -> (Maybe a) -> (Maybe a)
+merge_maybes _ y@(Just _) = y
+merge_maybes x@(Just _) Nothing = x
+merge_maybes Nothing Nothing = Nothing
+
+
+-- | Return the (thing contained in the) second argument if it is
+-- non-'Nothing'. Otherwise return the first argument.
+--
+-- ==== _Examples_
+--
+-- The second is preferred if it is non-'Nothing':
+--
+-- >>> merge_maybe 3 (Just 4)
+-- 4
+--
+-- However, if the second argument is 'Nothing', the first is
+-- returned:
+--
+-- >>> merge_maybe 1 Nothing
+-- 1
+--
+merge_maybe :: a -> Maybe a -> a
+merge_maybe x Nothing = x
+merge_maybe _ (Just y) = y
+
+