-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilterList.hs
More file actions
36 lines (23 loc) · 830 Bytes
/
FilterList.hs
File metadata and controls
36 lines (23 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{- Membuat prosedur filterlist yang menerima input list kemudian memisahkan sesuai parameter yang dipilih-}
filterlist :: [Int] -> (Int -> Bool) -> [Int]
isEmpty :: [Int] -> Bool
isEmpty l = null l
konso :: Int -> [Int] -> [Int]
konso e l = [e] ++ l
-- Fungsi filter
isPos :: Int -> Bool
isNeg :: Int -> Bool
isKabisat :: Int -> Bool
-- Fungsi isPos
isPos x = if x > 0 then True
else False
-- Fungsi isNeg
isNeg x = if x < 0 then True
else False
-- Fungsi isKabisat
isKabisat x = if ((((mod x 4 == 0) && (mod x 100 /= 0))) || ((mod x 100 == 0) && (mod x 400) == 0) ) then True
else False
filterlist l fungsi = if isEmpty l then []
else
if fungsi (head l) then konso (head l) ( filterlist (tail l) fungsi)
else (filterlist (tail l) fungsi)