Created
June 19, 2017 12:28
-
-
Save pesterhazy/4dac98a570b9534e56cace78b945bc62 to your computer and use it in GitHub Desktop.
ClojureScript data structures for queues (LIFO, FIFO)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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