http://zorba.io/modules/queue

Description

Before using any of the functions below please remember to import the module namespace:

import module namespace queue = "http://zorba.io/modules/queue";
Implementation of queue for items, using dynamic collections.

Entries in the queue must be structured items - that is, either JSON Objects or Arrays, or XML Nodes.

Module code

Here is the actual XQuery module code.

Imported modules

Authors

Daniel Turcanu, Sorin Nasoi

Version Declaration

xquery version "3.0" encoding "utf-8";

Namespaces

annhttp://zorba.io/annotations
collections-ddlhttp://zorba.io/modules/store/dynamic/collections/ddl
collections-dmlhttp://zorba.io/modules/store/dynamic/collections/dml
queuehttp://zorba.io/modules/queue
verhttp://zorba.io/options/versioning

Variables

queue:ERR-NS

queue:NOT-EXISTS

queue:EXISTS

Function Summary

create($name as xs:QName) as empty-sequence()

Create a queue with the name given.

front($name as xs:QName) as structured-item()?

Return the first item in the queue (the first added), without removing it.

back($name as xs:QName) as structured-item()?

Return the last item in the queue (the last added), without removing it.

pop($name as xs:QName) as structured-item()?

Return the first item in the queue, and remove it.

push($name as xs:QName, $value as structured-item()) as empty-sequence()

Add a new item to the queue; the queue will contain a copy of the given item.

empty($name as xs:QName) as xs:boolean

Checks if a queue exists and is empty.

size($name as xs:QName) as xs:integer

Count of items in the queue.

copy($destName as xs:QName, $sourceName as xs:QName) as empty-sequence()

Copy all items from source queue to a destination queue.

Functions

create#1

declare %ann:sequential function queue:create(
    $name as xs:QName
) as empty-sequence()
Create a queue with the name given. If a queue with the given name already exists, an error is raised.

Parameters

  • $name

    name of the new queue.

Returns

  • empty-sequence()

    an empty sequence.

Errors

  • queue:EXISTS

    if the queue identified by $name already exists.

front#1

declare function queue:front(
    $name as xs:QName
) as structured-item()?
Return the first item in the queue (the first added), without removing it.

Parameters

  • $name

    name of the queue.

Returns

  • structured-item()?

    the first item, or empty sequence if queue is empty.

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

back#1

declare function queue:back(
    $name as xs:QName
) as structured-item()?
Return the last item in the queue (the last added), without removing it.

Parameters

  • $name

    name of the queue.

Returns

  • structured-item()?

    the last item, or empty sequence if queue is empty.

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

pop#1

declare %ann:sequential function queue:pop(
    $name as xs:QName
) as structured-item()?
Return the first item in the queue, and remove it.

Parameters

  • $name

    name of the queue.

Returns

  • structured-item()?

    the first item, or empty sequence if queue is empty.

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

push#2

declare %ann:sequential function queue:push(
    $name as xs:QName,
    $value as structured-item()
) as empty-sequence()
Add a new item to the queue; the queue will contain a copy of the given item.

Parameters

  • $name

    name of the queue.

  • $value

    the item to be added.

Returns

  • empty-sequence()

    ()

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

empty#1

declare function queue:empty(
    $name as xs:QName
) as xs:boolean
Checks if a queue exists and is empty.

Parameters

  • $name

    name of the queue.

Returns

  • xs:boolean

    true is the queue is empty, false if it is not empty.

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

size#1

declare function queue:size(
    $name as xs:QName
) as xs:integer
Count of items in the queue.

Parameters

  • $name

    name of the queue.

Returns

  • xs:integer

    the count of items.

Errors

  • queue:NOT-EXISTS

    if the queue identified by $name does not exist.

Examples

copy#2

declare %ann:sequential function queue:copy(
    $destName as xs:QName,
    $sourceName as xs:QName
) as empty-sequence()
Copy all items from source queue to a destination queue.

If destination queue does not exist, it is created first.

If destination queue is not empty, the items are appended last.

Parameters

  • $destName

    name of the destination queue.

  • $sourceName

    name of the source queue.

Returns

  • empty-sequence()

    an empty sequence.

Examples