Skip to content

Commit 12483c6

Browse files
jolbyschani
authored andcommitted
Added IPrintable support for PersistentVector, PersistentHashMap
1 parent 0dedbde commit 12483c6

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/cljc/cljc/core.cljc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,8 @@ reduces them without incurring seq initialization"
14501450
(-as-transient [coll]
14511451
(TransientVector cnt shift (tv-editable-root root) (tv-editable-tail tail)))
14521452

1453+
IPrintable
1454+
(-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
14531455
;; Not yet ported from ClojureScript
14541456

14551457
;; IHash
@@ -1633,7 +1635,10 @@ reduces them without incurring seq initialization"
16331635

16341636
IEmptyableCollection
16351637
(-empty [coll]
1636-
(-with-meta cljc.core.PersistentVector/EMPTY meta)))
1638+
(-with-meta cljc.core.PersistentVector/EMPTY meta))
1639+
1640+
IPrintable
1641+
(-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll)))
16371642

16381643
(defn chunked-seq
16391644
([vec i off] (chunked-seq vec (array-for vec i) i off nil))
@@ -1701,6 +1706,9 @@ reduces them without incurring seq initialization"
17011706
(-invoke [coll k not-found]
17021707
(-lookup coll k not-found))
17031708

1709+
IPrintable
1710+
(-pr-seq [coll opts] (pr-sequential pr-seq "[" " " "]" opts coll))
1711+
17041712
;; IHash
17051713
;; (-hash [coll] (caching-hash coll hash-coll __hash))
17061714

@@ -2480,7 +2488,10 @@ reduces them without incurring seq initialization"
24802488
(-equiv [coll other] (equiv-sequential coll other))
24812489

24822490
IHash
2483-
(-hash [coll] (caching-hash coll hash-coll __hash)))
2491+
(-hash [coll] (caching-hash coll hash-coll __hash))
2492+
2493+
IPrintable
2494+
(-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll)))
24842495

24852496
(defn- create-inode-seq
24862497
([nodes]
@@ -2531,7 +2542,10 @@ reduces them without incurring seq initialization"
25312542
(-equiv [coll other] (equiv-sequential coll other))
25322543

25332544
IHash
2534-
(-hash [coll] (caching-hash coll hash-coll __hash)))
2545+
(-hash [coll] (caching-hash coll hash-coll __hash))
2546+
2547+
IPrintable
2548+
(-pr-seq [coll opts] (pr-sequential pr-seq "(" " " ")" opts coll)))
25352549

25362550
(defn- create-array-node-seq
25372551
([nodes] (create-array-node-seq nil nodes 0 nil))
@@ -2635,7 +2649,12 @@ reduces them without incurring seq initialization"
26352649

26362650
IEditableCollection
26372651
(-as-transient [coll]
2638-
(TransientHashMap. (EditSentinel.) root cnt has-nil? nil-val)))
2652+
(TransientHashMap. (EditSentinel.) root cnt has-nil? nil-val))
2653+
2654+
IPrintable
2655+
(-pr-seq [coll opts]
2656+
(let [pr-pair (fn [keyval opts] (pr-sequential pr-seq "" " " "" opts keyval))]
2657+
(pr-sequential pr-pair "{" ", " "}" opts coll))))
26392658

26402659
(set! cljc.core.PersistentHashMap/EMPTY (PersistentHashMap. nil 0 nil false nil 0))
26412660

test/clojurec/core_test.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@
487487
(pr \a \b) (pr " ")
488488
(pr '(1 2 3)) (pr " ")
489489
(pr (make-array 2)) (pr " ")
490+
(pr [1 2]) (pr " ")
491+
(pr {:a 1}) (pr " ")
490492
(pr #{1 2 3})))
491493
[true false
492494
-1 0 1
@@ -496,6 +498,8 @@
496498
\a \b
497499
'(1 2 3)
498500
[nil nil]
501+
[1 2]
502+
{:a 1}
499503
#{1 2 3}]))))
500504

501505
(deftest equality

0 commit comments

Comments
 (0)