Skip to content

Commit 2a8c2a9

Browse files
committed
CLJS-690: add sequence & sorted?
1 parent 1a8faf5 commit 2a8c2a9

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎devnotes/corelib.org‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ as macro
471471
* DONE seq
472472
* DONE seq?
473473
* seque
474-
* TODO sequence
474+
* DONE sequence
475475
* DONE sequential?
476476
* DONE set
477477
* set-error-handler!
@@ -492,7 +492,7 @@ as macro
492492
* DONE sorted-map-by
493493
* DONE sorted-set
494494
* DONE sorted-set-by
495-
* TODO sorted?
495+
* DONE sorted?
496496
* DONE special-symbol?
497497
* spit
498498
* DONE split-at
@@ -502,7 +502,7 @@ as macro
502502
* struct
503503
* struct-map
504504
* DONE subs
505-
* TODO subseq
505+
* DONE subseq
506506
* DONE subvec
507507
* TODO supers
508508
* DONE swap!

‎src/cljs/cljs/core.cljs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@
475475

476476
:else (throw (js/Error. (str coll "is not ISeqable"))))))
477477

478+
(defn ^seq sequence
479+
"Coerces coll to a (possibly empty) sequence, if it is not already
480+
one. Will not force a lazy seq. (sequence nil) yields ()"
481+
[coll]
482+
(if (seq? coll)
483+
coll
484+
(or (seq coll) ())))
485+
478486
(defn first
479487
"Returns the first item in the collection. Calls seq on its
480488
argument. If coll is nil, returns nil."
@@ -1120,6 +1128,10 @@ reduces them without incurring seq initialization"
11201128
"Returns true if coll satisfies ISequential"
11211129
[x] (satisfies? ISequential x))
11221130

1131+
(defn ^boolean sorted?
1132+
"Returns true if coll satisfies ISorted"
1133+
[x] (satisfies? ISorted x))
1134+
11231135
(defn ^boolean reduceable?
11241136
"Returns true if coll satisfies IReduce"
11251137
[x] (satisfies? IReduce x))

0 commit comments

Comments
 (0)