removeOrphans :: [NsItem] -- ^ List to remove orphans from
              -> [NsItem] -- ^ Orphan-free list
removeOrphans list =
  let children = S.fromList $ concatMap (names . (\(_, d, _) -> d)) list
  in  filter ((flip S.notMember children) . (\(n, _, _) -> n)) list

  where names (Just (DataDoc _ fds))                  = map (\(FD n _ _ _ _) -> n) fds
        names (Just (InterfaceDoc _ _ fds _ _ _ _ _ c)) = map (\(FD n _ _ _ _) -> n) fds ++ map (\(FD n _ _ _ _) -> n) (maybeToList c)
        names _                                       = []

-- | Whether a Name names something which should be documented
removeOrphans :: [NsItem] -- ^ List to remove orphans from
              -> [NsItem]
removeOrphans list =
  let children = S.fromList $ concatMap (names . (\(_, d, _) -> d)) list
  in  filter ((flip S.notMember children) . (\(n, _, _) -> n)) list

  where names (Just (DataDoc _ fds))                  = map (\(FD n _ _ _ _) -> n) fds
        names (Just (InterfaceDoc _ _ fds _ _ _ _ _ c)) = map (\(FD n _ _ _ _) -> n) fds ++ map (\(FD n _ _ _ _) -> n) (maybeToList c)
        names _                                       = []

-- | Whether a Name names something which should be documented
removeOrphans list =
  let children = S.fromList $ concatMap (names . (\(_, d, _) -> d)) list
  in  filter ((flip S.notMember children) . (\(n, _, _) -> n)) list

  where names (Just (DataDoc _ fds))                  = map (\(FD n _ _ _ _) -> n) fds
        names (Just (InterfaceDoc _ _ fds _ _ _ _ _ c)) = map (\(FD n _ _ _ _) -> n) fds ++ map (\(FD n _ _ _ _) -> n) (maybeToList c)
        names _                                       = []

-- | Whether a Name names something which should be documented