Idris2Doc : Data.Queue

Data.Queue

(source)
Immutable FIFO Queues

Definitions

recordQueue : Type->Type
  An immutable first-in first-out structure with amortized
O(1) enqueue and dequeue operations.

Totality: total
Visibility: export
Constructor: 
Q : Lista->SnocLista->Queuea

Projections:
.back : Queuea->SnocLista
.front : Queuea->Lista

Hints:
Eqa=>Eq (Queuea)
FoldableQueue
FunctorQueue
Monoid (Queuea)
Semigroup (Queuea)
Showa=>Show (Queuea)
TraversableQueue
empty : Queuea
  The empty `Queue`. O(1)

Totality: total
Visibility: export
fromList : Lista->Queuea
  Converts a list to a `Queue`, keeping the order of
elements. O(1)

Totality: total
Visibility: export
fromSnocList : SnocLista->Queuea
  Converts a `SnocList` to a `Queue`, keeping the order of
elements. O(1)

Totality: total
Visibility: export
toSnocList : Queuea->SnocLista
  Converts a `Queue` to a `SnocList`, keeping the order
of elements. O(n)

Totality: total
Visibility: export
enqueue : Queuea->a->Queuea
  Append a value at the back of the `Queue`. O(1)

Totality: total
Visibility: export
enqueueAll : Queuea->Lista->Queuea
  Append a list of values at the back of the `Queue`. O(1)

Totality: total
Visibility: export
dequeue : Queuea->Maybe (a, Queuea)
  Take a value from the front of the `Queue`.

In case of the front being empty, this transfers
the back to the front, which runs in O(n). However,
every element in the `Queue` is thus shifted at most
once before being dequeued, so this runs in amortized
O(1).

Totality: total
Visibility: export
prepend : a->Queuea->Queuea
  We can prepend an element to our `Queue`, making it the new
"oldest" element. O(1)

This is against the typical use case for a FIFO data
structure, but it allows us to conveniently implement
`peekOldest`.

Totality: total
Visibility: export
peekOldest : Queuea->Maybe (a, Queuea)
  Return the last element of the `Queue`, plus the unmodified
`Queue`.

Note: `peekOldest` might involve a rearrangement of the elements
just like `dequeue`. In order to keep our amortized O(1)
runtime behavior, the newly arranged `Queue` should be used
henceforth.

Totality: total
Visibility: export
(++) : Queuea->Queuea->Queuea
  Appends two `Queue`s. O(m + n)

Totality: total
Visibility: export
Fixity Declaration: infixr operator, level 7
length : Queuea->Nat
  Returns the length of the `Queue`. O(n).

Totality: total
Visibility: export
filter : (a->Bool) ->Queuea->Queuea
  Keeps only those values in a queue for which the given predicate
returns `True`.

Totality: total
Visibility: export
mapMaybe : (a->Maybeb) ->Queuea->Queueb
  Maps the values in a queue, keeping only those for which the given
function returns a `Just`.

Totality: total
Visibility: export