tagged literal | since v0.0-1424 | Edit |
A queue is defined by placing #queue
before a vector.
#queue [...]
Queues are the only core collection type that requires a tagged literal to
create, while the other collections have built-in delimiters ()
[]
{}
#{}
.
See PersistentQueue
for data structure details.
#queue []
;;=> #queue []
#queue [1 2 3]
;;=> #queue [1 2 3]
Some operations:
(def q #queue [1 2 3])
;;=> #queue [1 2 3]
(conj q 4)
;;=> #queue [1 2 3 4]
(pop q)
;;=> #queue [2 3]
(peek q)
;;=> 1
(defn read-queue
[form]
(when-not (vector? form)
(throw
#?(:clj (RuntimeException.
"Queue literal expects a vector for its elements.")
:cljs (js/Error.
"Queue literal expects a vector for its elements."))))
(list 'cljs.core/into 'cljs.core.PersistentQueue.EMPTY form))
(def ^:dynamic *cljs-data-readers*
(merge ;; assumes we can read all data_readers
#?(:clj *data-readers*)
{'queue read-queue
'uuid read-uuid
'inst read-inst
'js read-js}))