,
isListOk :: Bool
isListOk = length (filter isItemOk [1 .. 1000]) <= 3
, , . ( , , . , 1 .. 1000, 1.1000.)
- , , .
, length ( 1, , ) . length : , , , .
, (.. ) , , :
isNotLongerThan :: [a] -> Integer -> Bool
isNotLongerThan [] n = n >= 0
isNotLongerThan (_ : xs) n = n >= 1 && isNotLongerThan xs (n - 1)
isListOk :: Bool
isListOk = filter isItemOk [1 .. 1000] `isNotLongerThan` 3
, , , :
forNoMoreThan :: (a -> Bool) -> Integer -> [a] -> Bool
forNoMoreThan p n = (`isNotLongerThan` n) . filter p
isListOk :: Bool
isListOk = (isItemOk `forNoMoreThan` 3) [1 .. 1000]
Finally, as the hammar points out, if your threshold is small enough and fixed, you can simply use pattern matching to determine if the list is enough.
source
share