Batched queue, a sequential FIFO persistent collection.

Batched queue is an implementation of FIFO (conj onto rear, peek/pop from front) IPersistentList based on Okasaki’s Batched Queues.

Except for very special cases, it is idiomatic to use functions defined in coll.default rather than ones in this namespace.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;; Batched queue is a default queue implementation in Dunaj

;;; convenience functions for queues

(->que 1 2 3 4 5)
;;=> #<PersistentQueue [email protected]>

(que [1 2 3 4 5])
;;=> #<PersistentQueue [email protected]>

;; note that in CLJ format, there is no special syntax for queues.
;; you can use e.g. seq to print its contents.

(seq (->que 1 2 3 4 5))
;;=> (1 2 3 4 5)

;;; Using empty-que

(conj empty-que 1 2 3 4 5)
;;=> #<PersistentQueue [email protected]>

(into empty-que [1 2 3 4 5])
;;=> #<PersistentQueue [email protected]>

;; peek returns the front (first) item
(peek (->que 1 2 3 4 5))
;;=> 1

;; pop removes front (first) item
(seq (pop (->que 1 2 3 4 5)))
;;=> (2 3 4 5)

;; conj inserts into the rear
(seq (conj (->que 1 2 3 4 5) :foo))
;;=> (1 2 3 4 5 :foo)

batched-queue-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type ICollectionFactory

A Batched Queue factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of Batched Queue can be created with collection and ->collection.

1
2
3
4
5
6
7
8
9
10
(ns foo.bar
  (:api dunaj)
  (:require [dunaj.coll :refer [->collection collection]]
            [dunaj.coll.batched-queue :refer [batched-queue-factory]]))

(->collection batched-queue-factory 1 2 3 4 5)
;;=> #<PersistentQueue [email protected]>

(collection batched-queue-factory [1 2 3 4 5])
;;=> #<PersistentQueue [email protected]>

empty-batched-queue

Available since version 1.0 (view source)

not referred automatically

VAR of type BatchedQueue

An empty batched queue.