Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created June 19, 2017 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pesterhazy/4dac98a570b9534e56cace78b945bc62 to your computer and use it in GitHub Desktop.
Save pesterhazy/4dac98a570b9534e56cace78b945bc62 to your computer and use it in GitHub Desktop.
ClojureScript data structures for queues (LIFO, FIFO)
;; ClojureScript data structures for use as a queue
;;
;; Try in lumo
(require 'clojure.pprint)
(->> (map (fn [ds]
{"data" (pr-str ds)
"type" (pr-str (type ds))
"conj 3" (conj ds 3)
"peek" (peek ds)
"pop" (pop ds)})
['(1 2) [1 2] #queue [1 2]])
clojure.pprint/print-table)
;; results of main operations (conj, peek, pop) depending on data
;; structure
;;
;; | data | type | conj 3 | peek | pop |
;; |--------------+----------------------------+----------------+------+------------|
;; | (1 2) | cljs.core/List | (3 1 2) | 1 | (2) |
;; | [1 2] | cljs.core/PersistentVector | [1 2 3] | 2 | [1] |
;; | #queue [1 2] | cljs.core/PersistentQueue | #queue [1 2 3] | 1 | #queue [2] |
;;
;; Result: for FIFO semantics use #queue []; for LIFO semantics use '()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment