Write getLiteralArgs with foldr and without fromMaybe or monads

This commit is contained in:
Joseph C. Sible 2020-04-05 21:59:27 -04:00
parent 01f4423465
commit facf0d1e27
1 changed files with 5 additions and 4 deletions

View File

@ -289,10 +289,11 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
-- Get the literal options from a list of arguments,
-- up until the first non-literal one
getLiteralArgs :: [Token] -> [(Id, String)]
getLiteralArgs (first:rest) = fromMaybe [] $ do
str <- getLiteralString first
return $ (getId first, str) : getLiteralArgs rest
getLiteralArgs [] = []
getLiteralArgs = foldr go []
where
go first rest = case getLiteralString first of
Just str -> (getId first, str) : rest
Nothing -> []
-- Check a flag-option pair (such as -o errexit)
checkOptions (flag@(fid,flag') : opt@(oid,opt') : rest)