filterByPredicate
This commit is contained in:
@@ -7,3 +7,8 @@ main = do
|
||||
putStrLn $ "Примеры работы `isCongruent`"
|
||||
putStrLn $ "isCongruent 10 12 2: " ++ show (isCongruent 10 12 2)
|
||||
putStrLn $ "isCongruent 10 11 2: " ++ show (isCongruent 10 11 2)
|
||||
|
||||
putStrLn $ "\nПример работы `filterByPredicate`"
|
||||
let predicate x = x > 5
|
||||
putStrLn $ "filterByPredicate (>5) [1, 6, 3, 7, 2]: "
|
||||
++ show (filterByPredicate predicate [1 :: Int, 6, 3, 7, 2])
|
||||
@@ -1,6 +1,16 @@
|
||||
module Lib
|
||||
( isCongruent
|
||||
( isCongruent,
|
||||
filterByPredicate
|
||||
) where
|
||||
|
||||
isCongruent :: Int -> Int -> Int -> Bool
|
||||
isCongruent a b d = a `mod` d == b `mod` d
|
||||
|
||||
|
||||
filterByPredicate :: (a -> Bool) -> [a] -> [a]
|
||||
filterByPredicate _ [] = []
|
||||
filterByPredicate predicate (x:xs)
|
||||
| predicate x = x : filteredTail
|
||||
| otherwise = filteredTail
|
||||
where
|
||||
filteredTail = filterByPredicate predicate xs
|
||||
Reference in New Issue
Block a user