8

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?

Update

In the meantime I am using channels, (<!, (>! and go blocks and this seems to do the trick

yazz.com
  • 57,320
  • 66
  • 234
  • 385

2 Answers2

17

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
Shaun Lebron
  • 2,501
  • 28
  • 29
9

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

Community
  • 1
  • 1
Mike Fikes
  • 3,507
  • 14
  • 28