# Functional Queues

Denys Duchier

module
  x-oz://system/adt/Queue.ozf

This module provides a functional implemention of queues

## Exports

The modules exports the following constructors:

`{Queue.new ?Q}`
  returns a new functional queue instance `Q`, currently empty
`{Queue.newFromList +L ?Q}`
  returns a new functional queue instance `Q`, initialized with the elements of list `L`

## Instance API

Each functional queue instance `Q` has the following features:

`{Q.get ?V}`
  returns the next value `V` available from `Q`, or raises exception `empty` if none
`{Q.put +V}`
  enters a new value `V` into the queue
`{Q.getPut ?Old +New}`
  atomically, gets the next value `Old` available from `Q` and enters the value `New`. If `Q` was empty, `New` is `Old` and `Q` is still empty
`{Q.top ?V}`
  returns the next value `V` available from `Q` without actually removing it from `Q`
`{Q.toList ?L}`
  returns the list `L` of all values in `Q`
`{Q.toListKill ?L}`
  returns the list `L` of all values in `Q` and makes `Q` unusable until a subsequent `{Q.reset}`. This is more efficient that `{Q.toList ?L}` because no copy is required
`{Q.isEmpty ?B}`
  returns true iff `Q` is empty
`{Q.reset}`
  discards `Q`'s content and resets it to an empty queue
`{Q.clone ?Q2}`
  returns a new functional queue instance `Q2` which is a clone of `Q`