Vector.dedup and Order.equal

This commit is contained in:
Paul Chiusano 2016-10-04 20:53:51 -04:00
parent e3e134cb83
commit 9b4233e079
2 changed files with 14 additions and 6 deletions

View File

@ -73,11 +73,12 @@ tests = withResource Common.node (\_ -> pure ()) $ \node ->
"[1,2,3,4,5]"
, t "Vector.fold-balanced (+) 0 [1,2,3]" "6"
, t "Vector.dedup-adjacent (==_Number) [1,1,2,2,3,4,4,4,4,5]" "[1,2,3,4,5]"
, t "Vector.dedup Number.Order [1,2,1,5,4,2,4,4,3,5]" "[1,2,3,4,5]"
, t "Vector.range 0 10" "[0,1,2,3,4,5,6,7,8,9]"
, t "Vector.range 0 0" "[]"
, t "Vector.fold-left (+) 0 (Vector.replicate 5 1)" "5"
, t "Vector.sort Number.Order identity [5,2,1,3,4]" "[1,2,3,4,5]"
, t "Vector.sort (Order.invert Number.Order) identity [5,2,1,3,4]" "[5,4,3,2,1]"
, t "Vector.sort-by Number.Order identity [5,2,1,3,4]" "[1,2,3,4,5]"
, t "Vector.sort-by (Order.invert Number.Order) identity [5,2,1,3,4]" "[5,4,3,2,1]"
, t "Vector.bind 2nd (Vector.zip [1,2,3] [[1],[2],[3]])" "[1,2,3]"
, t "Vector.all? identity [True,True,True,True]" "True"
, t "Vector.all? identity [True,False,True,True]" "False"

View File

@ -33,6 +33,10 @@ set-1st new-1st p = Pair new-1st (rest p);
Order.compare : ∀ a . Order a -> a -> a -> Comparison;
Order.compare o a1 a2 = Order.Key.compare (Order.key o a1) (Order.key o a2);
Order.equal : ∀ a . Order a -> a -> a -> Boolean;
Order.equal o a a2 =
Comparison.fold False True False (Order.compare o a a2);
Order.tuple2 : ∀ a b . Order a -> Order b -> Order (a,b);
Order.tuple2 a b = Pair.Order a (Pair.Order b Unit.Order);
@ -80,11 +84,11 @@ Optional.lift-or f = a1 a2 ->
Vector.all? : ∀ a . (a -> Boolean) -> Vector a -> Boolean;
Vector.all? f vs = Vector.fold-balanced and True (Vector.map f vs);
Vector.sort : ∀ k a . Order k -> (a -> k) -> Vector a -> Vector a;
Vector.sort ok f v = Vector.sort-keyed (f `and-then` Order.key ok) v;
Vector.sort-by : ∀ k a . Order k -> (a -> k) -> Vector a -> Vector a;
Vector.sort-by ok f v = Vector.sort-keyed (f `and-then` Order.key ok) v;
Vector.sort' : ∀ a . Order a -> Vector a -> Vector a;
Vector.sort' o = Vector.sort o identity;
Vector.sort : ∀ a . Order a -> Vector a -> Vector a;
Vector.sort o = Vector.sort-by o identity;
Vector.last : ∀ a . Vector a -> Optional a;
Vector.last v = Vector.at (Vector.size v - 1) v;
@ -102,6 +106,9 @@ Vector.dedup-adjacent eq v =
[]
(Vector.map Vector.pure v);
Vector.dedup : ∀ a . Order a -> Vector a -> Vector a;
Vector.dedup o v = Vector.dedup-adjacent (Order.equal o) (Vector.sort o v);
Remote.map : ∀ a b . (a -> b) -> Remote a -> Remote b;
Remote.map f = Remote.bind (f `and-then` Remote.pure);