mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: add Pair.reverse and Map.reverse
This commit is contained in:
parent
9b9b0df90e
commit
58e280c553
@ -276,6 +276,9 @@
|
||||
@"{"
|
||||
m)]
|
||||
(String.append &res " }")))
|
||||
|
||||
(defn reverse [m]
|
||||
(from-array &(Array.copy-map &Pair.reverse &(to-array m))))
|
||||
)
|
||||
|
||||
(deftype (SetBucket a) [entries (Array a)])
|
||||
|
@ -33,4 +33,7 @@
|
||||
(defn > [p1 p2]
|
||||
(PairRef.> &p1 &p2))
|
||||
|
||||
(doc reverse "reverses a `Pair` `p` such that its first member is its second member and vice versa.")
|
||||
(defn reverse [p]
|
||||
(Pair.init @(Pair.b p) @(Pair.a p)))
|
||||
)
|
||||
|
@ -197,6 +197,11 @@
|
||||
(Map.get &{(Pair.init 1 2) 3} &(Pair.init 1 2))
|
||||
"Pairs work as keys"
|
||||
)
|
||||
(assert-equal test
|
||||
&{1 @"hi" 2 @"bye"}
|
||||
&(Map.reverse &{@"hi" 1 @"bye" 2})
|
||||
"reverse works"
|
||||
)
|
||||
(assert-equal test
|
||||
1
|
||||
(Set.length &(Set.put (Set.create) "1"))
|
||||
|
@ -21,4 +21,9 @@
|
||||
"comparison works with (Ref (Pair String Int)) I")
|
||||
(assert-false test
|
||||
(< &(Pair.init @"a" 2) &(Pair.init @"a" 1))
|
||||
"comparison works with (Ref (Pair String Int)) II"))
|
||||
"comparison works with (Ref (Pair String Int)) II")
|
||||
(assert-equal test
|
||||
&(Pair.init 2 @"a")
|
||||
&(Pair.reverse &(Pair.init @"a" 2))
|
||||
"reverse works")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user