{-# LANGUAGE OverloadedStrings #-}
module CLI.Internal
( translateCommands,
)
where
import qualified Data.Map as Map
import qualified Data.Text as T
translateCommands :: Map.Map T.Text T.Text -> [T.Text] -> [T.Text]
translateCommands :: Map Text Text -> [Text] -> [Text]
translateCommands mp :: Map Text Text
mp = (Text -> [Text]) -> [Text] -> [Text]
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Map Text Text -> Text -> [Text]
lineToCommands Map Text Text
mp)
lineToCommands :: Map.Map T.Text T.Text -> T.Text -> [T.Text]
lineToCommands :: Map Text Text -> Text -> [Text]
lineToCommands mp :: Map Text Text
mp line :: Text
line =
case Text -> Text -> [Text]
T.splitOn "," Text
line of
[l :: Text
l] ->
case Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Text
l Map Text Text
mp of
Just c :: Text
c -> Map Text Text -> Text -> [Text]
lineToCommands Map Text Text
mp Text
c
Nothing -> [Text
l]
xs :: [Text]
xs -> [Text]
xs [Text] -> (Text -> [Text]) -> [Text]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Map Text Text -> Text -> [Text]
lineToCommands Map Text Text
mp