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, -- Get the literal options from a list of arguments,
-- up until the first non-literal one -- up until the first non-literal one
getLiteralArgs :: [Token] -> [(Id, String)] getLiteralArgs :: [Token] -> [(Id, String)]
getLiteralArgs (first:rest) = fromMaybe [] $ do getLiteralArgs = foldr go []
str <- getLiteralString first where
return $ (getId first, str) : getLiteralArgs rest go first rest = case getLiteralString first of
getLiteralArgs [] = [] Just str -> (getId first, str) : rest
Nothing -> []
-- Check a flag-option pair (such as -o errexit) -- Check a flag-option pair (such as -o errexit)
checkOptions (flag@(fid,flag') : opt@(oid,opt') : rest) checkOptions (flag@(fid,flag') : opt@(oid,opt') : rest)