-
Notifications
You must be signed in to change notification settings - Fork 1
/
lyh07.hs
48 lines (33 loc) · 1.19 KB
/
lyh07.hs
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
37
38
39
40
41
42
43
44
45
46
47
48
-- LYH Chapter 7. Modules --
import Data.List
import Data.Function (on)
-- More list-related functions
-- `intersperse', `intercalate', `transpose', `concat'
join xs xss = concat (intersperse xs xss)
join' = intercalate
-- `iterate'
twoPowers = iterate (*2) 1
-- `sort', `group', `groupBy', `nub', `nubBy'
-- A codewars kata
uniqueInOrder :: (Ord a, Eq a) => [a] -> [a]
uniqueInOrder = sort . nub
uniqueInOrder' :: (Ord a, Eq a) => [a] -> [a]
uniqueInOrder' = nub . sort
uniqueInOrder'' :: (Ord a, Eq a) => [a] -> [a]
uniqueInOrder'' = map head . group . sort
-- `inits', `tails'
-- `find' (-> Maybe a), `findIndex' (-> Maybe a), `findIndices' (-> [a])
-- `isPrefixOf', `isInfixOf', `isSuffixOf'
-- `elemIndex' (-> Maybe a), `elemIndices' (-> [a])
-- `delete', `deleteBy' `(\\)'
-- `union', `unionBy', `intersect', `intersectBy'
-- `insert'
-- `generic{Length,Take,Drop,SplitAt,Index,Replicate}' and
-- length,take,drop,splitAt,(!!), replicate
-- `on' from Data.Function
sameSign :: (Num a, Ord a) => a -> a -> Bool
sameSign = (==) `on` (compare 0)
sameSign' :: (Num a, Ord a) => a -> a -> Bool
sameSign' = (==) `on` signum
-- `sortBy', `insertBy', `maximumBy', `minimumBy'
-- NEXT: Data.Char