flipMaybe :: [Maybe a] -> Maybe [a]
flipMaybe list = 
  if not sawNothing
  then Just result
  else Nothing
  where 
    (sawNothing, result) = foldr folder (False, []) list
    folder m (b, acc) = 
      if b 
      then (True, [])
      else case m of 
        (Just n) -> (False, n : acc)
        _        -> (True, [])

-- Next: SmallLibraryForEitherChapter12.hs
flipMaybe :: [Maybe a] -> Maybe [a]
flipMaybe list = 
  if not sawNothing
  then Just result
  else Nothing
  where 
    (sawNothing, result) = foldr folder (False, []) list
    folder m (b, acc) = 
      if b 
      then (True, [])
      else case m of 
        (Just n) -> (False, n : acc)
        _        -> (True, [])

-- Next: SmallLibraryForEitherChapter12.hs
flipMaybe list = 
  if not sawNothing
  then Just result
  else Nothing
  where 
    (sawNothing, result) = foldr folder (False, []) list
    folder m (b, acc) = 
      if b 
      then (True, [])
      else case m of 
        (Just n) -> (False, n : acc)
        _        -> (True, [])

-- Next: SmallLibraryForEitherChapter12.hs