mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-08 05:51:09 -07:00
Implement findFirst in terms of foldr
This commit is contained in:
parent
b0dbc79f69
commit
b3c04ce3d0
1 changed files with 7 additions and 8 deletions
|
@ -388,14 +388,13 @@ parents params = getPath (parentMap params)
|
|||
-- Find the first match in a list where the predicate is Just True.
|
||||
-- Stops if it's Just False and ignores Nothing.
|
||||
findFirst :: (a -> Maybe Bool) -> [a] -> Maybe a
|
||||
findFirst p l =
|
||||
case l of
|
||||
[] -> Nothing
|
||||
(x:xs) ->
|
||||
findFirst p = foldr go Nothing
|
||||
where
|
||||
go x acc =
|
||||
case p x of
|
||||
Just True -> return x
|
||||
Just False -> Nothing
|
||||
Nothing -> findFirst p xs
|
||||
Nothing -> acc
|
||||
|
||||
-- Check whether a word is entirely output from a single command
|
||||
tokenIsJustCommandOutput t = case t of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue