Skip to content

Commit c6a76b8

Browse files
committed
Merge pull request #4 from joneshf/master
Added sortBy.
2 parents 0ab61ee + 9393581 commit c6a76b8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373

7474
sort :: forall a. (Ord a) => [a] -> [a]
7575

76+
sortBy :: forall a. (a -> a -> Ordering) -> [a] -> [a]
77+
7678
tail :: forall a. [a] -> Maybe [a]
7779

7880
take :: forall a. Prim.Number -> [a] -> [a]

src/Data/Array.purs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Data.Array
2929
, nub
3030
, nubBy
3131
, sort
32+
, sortBy
3233
) where
3334

3435
import Data.Maybe
@@ -263,12 +264,15 @@ nubBy _ [] = []
263264
nubBy (==) (x:xs) = x : nubBy (==) (filter (\y -> not (x == y)) xs)
264265

265266
sort :: forall a. (Ord a) => [a] -> [a]
266-
sort xs = sortJS comp xs
267+
sort xs = sortBy compare xs
268+
269+
sortBy :: forall a. (a -> a -> Ordering) -> [a] -> [a]
270+
sortBy comp xs = sortJS comp' xs
267271
where
268-
comp x y = case compare x y of
269-
GT -> 1
270-
EQ -> 0
271-
LT -> -1
272+
comp' x y = case comp x y of
273+
GT -> 1
274+
EQ -> 0
275+
LT -> -1
272276

273277
foreign import sortJS
274278
"function sortJS (f) {\

0 commit comments

Comments
 (0)