diff options
Diffstat (limited to 'compiler/utils/Util.hs')
-rw-r--r-- | compiler/utils/Util.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/utils/Util.hs b/compiler/utils/Util.hs index 84799aed0b..0c7bb4a189 100644 --- a/compiler/utils/Util.hs +++ b/compiler/utils/Util.hs @@ -30,7 +30,7 @@ module Util ( dropWhileEndLE, spanEnd, last2, - foldl1', foldl2, count, all2, + foldl1', foldl2, count, countWhile, all2, lengthExceeds, lengthIs, lengthIsNot, lengthAtLeast, lengthAtMost, lengthLessThan, @@ -705,6 +705,12 @@ count p = go 0 go !n (x:xs) | p x = go (n+1) xs | otherwise = go n xs +countWhile :: (a -> Bool) -> [a] -> Int +-- Length of an /initial prefix/ of the list satsifying p +countWhile p = go 0 + where go !n (x:xs) | p x = go (n+1) xs + go !n _ = n + {- @splitAt@, @take@, and @drop@ but with length of another list giving the break-off point: |