I can't seem to find any documentation on the Clojurescript cljs.core.PersistentQueue. Should I be using it at all? Or should I be using another method of making a Clojurescript queue?
In the meantime I am using channels, (<!, (>!
and go blocks and this seems to do the trick
ClojureScript actually has a tagged literal #queue []
for creating queues, which I found after putting Mike's answer into a repl
cljs.user=> cljs.core/PersistentQueue.EMPTY
#queue []
cljs.user=> #queue []
#queue []
cljs.user=> (def q #queue [1 2 3])
#queue [1 2 3]
cljs.user=> (conj q 4)
#queue [1 2 3 4]
cljs.user=> (pop q)
#queue [2 3]
cljs.user=> (peek q)
1
A PersistentQueue
is another persistent data structure with different behavior and performance characteristics when compared to list, vector, map, and set. If you look at the docstrings for pop
and peek
, for example, you will see this datatype being referred to as "queue".
Since it has no literal syntax, you have to start off by creating an empty one using cljs.core.PersistentQueue/EMPTY
.
This post provides a good high-level summary of the Clojure equivalent https://stackoverflow.com/a/2495105
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With