findFctyMthds :: [SliceDecl] -> Map.Map [String] [MethodDecl]
findFctyMthds asts = mapMaybeReverseKey (\k v -> mFctyMthds k) interfaces
  where
    interfaces = Map.unions . map (findInterfaces []) $ asts
    
    isFcty k = endswith "Factory" (head k) && Map.member (replaceTail "Factory" "" (head k) : tail k) interfaces
    
    mFctyMthds k = if isFcty k 
                   then Map.lookup k interfaces >>= \(InterfaceDecl _ _ mthds) -> Just mthds
                   else Nothing
                                              
    mapMaybeReverseKey :: ([String] -> a -> Maybe b) -> Map.Map [String] a -> Map.Map [String] b 
    mapMaybeReverseKey f m = go Map.empty (Map.toList m)
      where
        go acc []         = acc
        go acc ((k,v):xs) = case f k v of (Just x) -> go (Map.insert (reverse k) x acc) xs
                                          Nothing  -> go acc xs
findFctyMthds :: [SliceDecl] -> Map.Map [String] [MethodDecl]
findFctyMthds asts = mapMaybeReverseKey (\k v -> mFctyMthds k) interfaces
  where
    interfaces = Map.unions . map (findInterfaces []) $ asts
    
    isFcty k = endswith "Factory" (head k) && Map.member (replaceTail "Factory" "" (head k) : tail k) interfaces
    
    mFctyMthds k = if isFcty k 
                   then Map.lookup k interfaces >>= \(InterfaceDecl _ _ mthds) -> Just mthds
                   else Nothing
                                              
    mapMaybeReverseKey :: ([String] -> a -> Maybe b) -> Map.Map [String] a -> Map.Map [String] b 
    mapMaybeReverseKey f m = go Map.empty (Map.toList m)
      where
        go acc []         = acc
        go acc ((k,v):xs) = case f k v of (Just x) -> go (Map.insert (reverse k) x acc) xs
                                          Nothing  -> go acc xs
findFctyMthds asts = mapMaybeReverseKey (\k v -> mFctyMthds k) interfaces
  where
    interfaces = Map.unions . map (findInterfaces []) $ asts
    
    isFcty k = endswith "Factory" (head k) && Map.member (replaceTail "Factory" "" (head k) : tail k) interfaces
    
    mFctyMthds k = if isFcty k 
                   then Map.lookup k interfaces >>= \(InterfaceDecl _ _ mthds) -> Just mthds
                   else Nothing
                                              
    mapMaybeReverseKey :: ([String] -> a -> Maybe b) -> Map.Map [String] a -> Map.Map [String] b 
    mapMaybeReverseKey f m = go Map.empty (Map.toList m)
      where
        go acc []         = acc
        go acc ((k,v):xs) = case f k v of (Just x) -> go (Map.insert (reverse k) x acc) xs
                                          Nothing  -> go acc xs