mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-09-20 10:39:22 +08:00
Implement findFirst in terms of foldr
This commit is contained in:
@@ -388,14 +388,13 @@ parents params = getPath (parentMap params)
|
|||||||
-- Find the first match in a list where the predicate is Just True.
|
-- Find the first match in a list where the predicate is Just True.
|
||||||
-- Stops if it's Just False and ignores Nothing.
|
-- Stops if it's Just False and ignores Nothing.
|
||||||
findFirst :: (a -> Maybe Bool) -> [a] -> Maybe a
|
findFirst :: (a -> Maybe Bool) -> [a] -> Maybe a
|
||||||
findFirst p l =
|
findFirst p = foldr go Nothing
|
||||||
case l of
|
where
|
||||||
[] -> Nothing
|
go x acc =
|
||||||
(x:xs) ->
|
case p x of
|
||||||
case p x of
|
Just True -> return x
|
||||||
Just True -> return x
|
Just False -> Nothing
|
||||||
Just False -> Nothing
|
Nothing -> acc
|
||||||
Nothing -> findFirst p xs
|
|
||||||
|
|
||||||
-- Check whether a word is entirely output from a single command
|
-- Check whether a word is entirely output from a single command
|
||||||
tokenIsJustCommandOutput t = case t of
|
tokenIsJustCommandOutput t = case t of
|
||||||
|
Reference in New Issue
Block a user