summaryrefslogtreecommitdiff
path: root/lib/stdlib/doc/src/queue.xml
blob: 480ca89963a12319dec12e85871053a7f3f4593c (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2023</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>queue</title>
    <prepared>Joe</prepared>
    <responsible>Bjarne D&auml;cker</responsible>
    <docno>1</docno>
    <approved>Bjarne D&auml;cker</approved>
    <checked></checked>
    <date>1997-01-15</date>
    <rev>B</rev>
    <file>queue.xml</file>
  </header>
  <module since="">queue</module>
  <modulesummary>Abstract data type for FIFO queues.</modulesummary>
  <description>
    <p>This module provides (double-ended) FIFO queues
      in an efficient manner.</p>

    <p>All functions fail with reason <c>badarg</c> if arguments
      are of wrong type, for example, queue arguments are not
      queues, indexes are not integers, and list arguments are
      not lists. Improper lists cause internal crashes.
      An index out of range for a queue also causes
      a failure with reason <c>badarg</c>.</p>
    <p>Some functions, where noted, fail with reason <c>empty</c>
      for an empty queue.</p>

    <p>The data representing a queue as used by this module is to be
    regarded as opaque by other modules.  In abstract terms, the
    representation is a composite type of existing Erlang terms. See
    note on <seeguide
    marker="system/reference_manual:data_types#no_user_types">data
    types</seeguide>. Any code assuming knowledge of the format is
    running on thin ice.</p>

    <p>All operations have an amortized O(1) running time, except
      <seemfa marker="#all/2"><c>all/2</c></seemfa>,
      <seemfa marker="#any/2"><c>any/2</c></seemfa>,
      <seemfa marker="#delete/2"><c>delete/2</c></seemfa>,
      <seemfa marker="#delete_r/2"><c>delete_r/2</c></seemfa>,
      <seemfa marker="#delete_with/2"><c>delete_with/2</c></seemfa>,
      <seemfa marker="#delete_with_r/2"><c>delete_with_r/2</c></seemfa>,
      <seemfa marker="#filter/2"><c>filter/2</c></seemfa>,
      <seemfa marker="#filtermap/2"><c>filtermap/2</c></seemfa>,
      <seemfa marker="#fold/3"><c>fold/3</c></seemfa>,
      <seemfa marker="#join/2"><c>join/2</c></seemfa>,
      <seemfa marker="#len/1"><c>len/1</c></seemfa>,
      <seemfa marker="#member/2"><c>member/2</c></seemfa>,
      <seemfa marker="#split/2"><c>split/2</c></seemfa> that have O(n).
      To minimize the size of a queue minimizing
      the amount of garbage built by queue operations, the queues
      do not contain explicit length information, and that is
      why <c>len/1</c> is O(n). If better performance for this
      particular operation is essential, it is easy for
      the caller to keep track of the length.</p>

    <p>Queues are double-ended. The mental picture of
      a queue is a line of people (items) waiting for
      their turn. The queue front is the end with the item
      that has waited the longest. The queue rear is the end
      an item enters when it starts to wait. If instead using
      the mental picture of a list, the front is called head
      and the rear is called tail.</p>

    <p>Entering at the front and exiting at the rear
      are reverse operations on the queue.</p>

    <p>This module has three sets of interface functions: the
      <em>"Original API"</em>, the <em>"Extended API"</em>, and the <em>"Okasaki API"</em>.</p>

    <p>The "Original API" and the "Extended API" both use the
      mental picture of a waiting line of items. Both
      have reverse operations suffixed "_r".</p>

    <p>The "Original API" item removal functions return compound
      terms with both the removed item and the resulting queue.
      The "Extended API" contains alternative functions that build
      less garbage and functions for just inspecting the
      queue ends. Also the "Okasaki API" functions build less garbage.</p>

    <p>The "Okasaki API" is inspired by "Purely Functional Data Structures"
      by Chris Okasaki. It regards queues as lists.
      This API is by many regarded as strange and avoidable.
      For example, many reverse operations have lexically reversed names,
      some with more readable but perhaps less understandable aliases.</p>
  </description>

 

  <datatypes>
    <datatype>
      <name name="queue" n_vars="1"/>
      <desc><p>As returned by
        <seemfa marker="#new/0"><c>new/0</c></seemfa>.</p></desc>
    </datatype>
    <datatype>
      <name name="queue" n_vars="0"/>
    </datatype>
  </datatypes>

  <funcs>
    <fsdescription>
      <title>Original API</title>
    </fsdescription>
    <func>
      <name name="all" arity="2" since="OTP 24.0"/>
      <fsummary>Return <c>true</c> if all items in a queue satisfy
        <c>Pred</c>.</fsummary>
      <desc>
        <p>Returns <c>true</c> if <c><anno>Pred</anno>(<anno>Item</anno>)</c>
          returns <c>true</c> for all items <c><anno>Item</anno></c> in
          <c><anno>Q</anno></c>, otherwise <c>false</c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
2> <input>queue:all(fun (E) -> E > 3 end, Queue).</input>
false
3> <input>queue:all(fun (E) -> E > 0 end, Queue).</input>
true</pre>
      </desc>
    </func>

    <func>
      <name name="any" arity="2" since="OTP 24.0"/>
      <fsummary>Return <c>true</c> if any of the items in a queue satisfy
        <c>Pred</c>.</fsummary>
      <desc>
        <p>Returns <c>true</c> if <c><anno>Pred</anno>(<anno>Item</anno>)</c>
          returns <c>true</c> for at least one item <c><anno>Item</anno></c>
          in <c><anno>Q</anno></c>, otherwise <c>false</c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
2> <input>queue:any(fun (E) -> E > 10 end, Queue).</input>
false
3> <input>queue:any(fun (E) -> E > 3 end, Queue).</input>
true</pre>
      </desc>
    </func>

    <func>
      <name name="delete" arity="2" since="OTP 24.0"/>
      <fsummary>Delete an item from the front of a queue.</fsummary>
      <desc>
        <p>Returns a copy of <c><anno>Q1</anno></c> where the first item
          matching <c><anno>Item</anno></c> is deleted, if there is such an
          item.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
2> <input>Queue1 = queue:delete(3, Queue).</input>
3> <input>queue:member(3, Queue1).</input>
false</pre>
      </desc>
    </func>

    <func>
      <name name="delete_r" arity="2" since="OTP 24.0"/>
      <fsummary>Delete an item from the rear of a queue.</fsummary>
      <desc>
        <p>Returns a copy of <c><anno>Q1</anno></c> where the last item
          matching <c><anno>Item</anno></c> is deleted, if there is such an
          item.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,3,5]).</input>
2> <input>Queue1 = queue:delete_r(3, Queue).</input>
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="delete_with" arity="2" since="OTP 24.0"/>
      <fsummary>Delete an item matching a predicate from the front of a
        queue.</fsummary>
      <desc>
        <p>Returns a copy of <c><anno>Q1</anno></c> where the first item
          for which <c><anno>Pred</anno></c> returns <c>true</c> is deleted,
          if there is such an item.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([100,1,2,3,4,5]).</input>
2> <input>Queue1 = queue:delete_with(fun (E) -> E > 0, Queue).</input>
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="delete_with_r" arity="2" since="OTP 24.0"/>
      <fsummary>Delete an item matching a predicate from the rear of a
        queue.</fsummary>
      <desc>
        <p>Returns a copy of <c><anno>Q1</anno></c> where the last item
          for which <c><anno>Pred</anno></c> returns <c>true</c> is deleted,
          if there is such an item.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5,100]).</input>
2> <input>Queue1 = queue:delete_with(fun (E) -> E > 10, Queue).</input>
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="filter" arity="2" since=""/>
      <fsummary>Filter a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of calling
          <c><anno>Fun</anno>(<anno>Item</anno>)</c> on all items in
          <c><anno>Q1</anno></c>.</p>
        <p>If <c><anno>Fun</anno>(<anno>Item</anno>)</c> returns <c>true</c>,
          <c>Item</c> is copied to the result queue. If it returns <c>false</c>,
          <c><anno>Item</anno></c> is not copied. If it returns a list,
          the list elements are inserted instead of <c>Item</c> in the
          result queue.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue1 = queue:filter(fun (E) -> E > 2 end, Queue).</input>
{[5],[3,4]}
3> <input>queue:to_list(Queue1).</input>
[3,4,5]</pre>
        <p>So, <c><anno>Fun</anno>(<anno>Item</anno>)</c> returning
          <c>[<anno>Item</anno>]</c> is thereby
          semantically equivalent to returning <c>true</c>, just
          as returning <c>[]</c> is semantically equivalent to
          returning <c>false</c>. But returning a list builds
          more garbage than returning an atom.</p>
          <p><em>Example 2:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue1 = queue:filter(fun (E) -> [E, E+1] end, Queue).</input>
{[6,5,5,4,4,3],[1,2,2,3]}
3> <input>queue:to_list(Queue1).</input>
[1,2,2,3,3,4,4,5,5,6]</pre>
      </desc>
    </func>

    <func>
      <name name="filtermap" arity="2" since="OTP 24.0"/>
      <fsummary>Filter and map a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of calling
          <c><anno>Fun</anno>(<anno>Item</anno>)</c> on all items in
          <c><anno>Q1</anno></c>.</p>
        <p>If <c><anno>Fun</anno>(<anno>Item</anno>)</c> returns <c>true</c>,
          <c>Item</c> is copied to the result queue. If it returns <c>false</c>,
          <c><anno>Item</anno></c> is not copied. If it returns
          <c>{true, NewItem}</c>, the queue element at this position is replaced
          with <c>NewItem</c> in the result queue.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue1 = queue:filtermap(fun (E) -> E > 2 end, Queue).</input>
{[5],[3,4]}
3> <input>queue:to_list(Queue1).</input>
[3,4,5]
4> <input>Queue1 = queue:filtermap(fun (E) -> {true, E+100} end, Queue).</input>
{"ihg","ef"}
5> <input>queue:to_list(Queue1).</input>
"efghi</pre>
      </desc>
    </func>

    <func>
      <name name="fold" arity="3" since="OTP 24.0"/>
      <fsummary>Fold a function over a queue.</fsummary>
      <desc>
        <p>Calls <c><anno>Fun</anno>(<anno>Item</anno>, <anno>AccIn</anno>)</c>
          on successive items <c>Item</c> of <c>Queue</c>, starting
          with <c><anno>AccIn</anno> == <anno>Acc0</anno></c>. The queue is
          traversed in queue order, that is, from front to rear.
          <c><anno>Fun</anno>/2</c> must return a new accumulator, which is
          passed to the next call. The function returns the final value of
          the accumulator. <c><anno>Acc0</anno></c> is returned if the queue is
          empty.</p>
        <p><em>Example:</em></p>
        <pre>
1> <input>queue:fold(fun(X, Sum) -> X + Sum end, 0, queue:from_list([1,2,3,4,5])).</input>
15
2> <input>queue:fold(fun(X, Prod) -> X * Prod end, 1, queue:from_list([1,2,3,4,5])).</input>
120</pre>
      </desc>
    </func>

    <func>
      <name name="from_list" arity="1" since=""/>
      <fsummary>Convert a list to a queue.</fsummary>
      <desc>
        <p>Returns a queue containing the items in <c><anno>L</anno></c> in the
          same order; the head item of the list becomes the front
          item of the queue.</p>
      </desc>
    </func>

    <func>
      <name name="in" arity="2" since=""/>
      <fsummary>Insert an item at the rear of a queue.</fsummary>
      <desc>
        <p>Inserts <c><anno>Item</anno></c> at the rear of queue
          <c><anno>Q1</anno></c>.
          Returns the resulting queue <c><anno>Q2</anno></c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue1 = queue:in(100, Queue).</input>
{[100,5,4,3],[1,2]}
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4,5,100]</pre>
      </desc>
    </func>

    <func>
      <name name="in_r" arity="2" since=""/>
      <fsummary>Insert an item at the front of a queue.</fsummary>
      <desc>
        <p>Inserts <c><anno>Item</anno></c> at the front of queue
          <c><anno>Q1</anno></c>.
          Returns the resulting queue <c><anno>Q2</anno></c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue1 = queue:in_r(100, Queue).</input>
{[5,4,3],[100,1,2]}
3> <input>queue:to_list(Queue1).</input>
[100,1,2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="is_empty" arity="1" since=""/>
      <fsummary>Test if a queue is empty.</fsummary>
      <desc>
        <p>Tests if <c><anno>Q</anno></c> is empty and returns <c>true</c> if
          so, otherwise <c>false</c>.</p>
      </desc>
    </func>

    <func>
      <name name="is_queue" arity="1" since=""/>
      <fsummary>Test if a term is a queue.</fsummary>
      <desc>
        <p>Tests if <c><anno>Term</anno></c> is a queue and returns
        <c>true</c> if so, otherwise <c>false</c>.  Note that the test
        will return <c>true</c> for a term coinciding with the
        representation of a queue, even when not constructed by thus
        module.  See also note on <seeguide
        marker="system/reference_manual:data_types#no_user_types">data
        types</seeguide>.</p>
      </desc>
    </func>

    <func>
      <name name="join" arity="2" since=""/>
      <fsummary>Join two queues.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q3</anno></c> that is the result of joining
          <c><anno>Q1</anno></c> and <c><anno>Q2</anno></c> with
          <c><anno>Q1</anno></c> in front of <c><anno>Q2</anno></c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue1 = queue:from_list([1,3]).</input>
{[3],[1]}
2> <input>Queue2 = queue:from_list([2,4]).</input>
{[4],[2]}
3> <input>queue:to_list(queue:join(Queue1, Queue2)).</input>
[1,3,2,4]</pre>
      </desc>
    </func>

    <func>
      <name name="len" arity="1" since=""/>
      <fsummary>Get the length of a queue.</fsummary>
      <desc>
        <p>Calculates and returns the length of queue <c><anno>Q</anno></c>.</p>
      </desc>
    </func>

    <func>
      <name name="member" arity="2" since=""/>
      <fsummary>Test if an item is in a queue.</fsummary>
      <desc>
        <p>Returns <c>true</c> if <c><anno>Item</anno></c> matches some element
          in <c><anno>Q</anno></c>, otherwise <c>false</c>.</p>
      </desc>
    </func>

    <func>
      <name name="new" arity="0" since=""/>
      <fsummary>Create an empty queue.</fsummary>
      <desc>
        <p>Returns an empty queue.</p>
      </desc>
    </func>

    <func>
      <name name="out" arity="1" since=""/>
      <fsummary>Remove the front item from a queue.</fsummary>
      <desc>
        <p>Removes the item at the front of queue <c><anno>Q1</anno></c>.
          Returns tuple <c>{{value, <anno>Item</anno>}, <anno>Q2</anno>}</c>,
          where <c><anno>Item</anno></c> is the item removed and
          <c><anno>Q2</anno></c> is the resulting queue. If
          <c><anno>Q1</anno></c> is empty, tuple
          <c>{empty, <anno>Q1</anno>}</c> is returned.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>{{value, 1=Item}, Queue1} = queue:out(Queue).</input>
{{value,1},{[5,4,3],[2]}}
3> <input>queue:to_list(Queue1).</input>
[2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="out_r" arity="1" since=""/>
      <fsummary>Remove the rear item from a queue.</fsummary>
      <desc>
        <p>Removes the item at the rear of queue <c><anno>Q1</anno></c>.
          Returns tuple <c>{{value, <anno>Item</anno>}, <anno>Q2</anno>}</c>,
          where <c><anno>Item</anno></c> is the item removed and
          <c><anno>Q2</anno></c> is the new queue. If <c><anno>Q1</anno></c> is
          empty, tuple <c>{empty, <anno>Q1</anno>}</c> is returned.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>{{value, 5=Item}, Queue1} = queue:out_r(Queue).</input>
{{value,5},{[4,3],[1,2]}}
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4]</pre>
      </desc>
    </func>

    <func>
      <name name="reverse" arity="1" since=""/>
      <fsummary>Reverse a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> containing the items of
          <c><anno>Q1</anno></c> in the reverse order.</p>
      </desc>
    </func>

    <func>
      <name name="split" arity="2" since=""/>
      <fsummary>Split a queue in two.</fsummary>
      <desc>
        <p>Splits <c><anno>Q1</anno></c> in two. The <c><anno>N</anno></c>
          front items are put in <c><anno>Q2</anno></c> and the rest in
          <c><anno>Q3</anno></c>.</p>
      </desc>
    </func>

    <func>
      <name name="to_list" arity="1" since=""/>
      <fsummary>Convert a queue to a list.</fsummary>
      <desc>
        <p>Returns a list of the items in the queue in the same order;
          the front item of the queue becomes the head of the list.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>List == queue:to_list(Queue).</input>
true</pre>
      </desc>
    </func>
  </funcs>

 

  <funcs>
    <fsdescription>
      <title>Extended API</title>
    </fsdescription>
    <func>
      <name name="drop" arity="1" since=""/>
      <fsummary>Remove the front item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the front item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue = queue:drop(Queue).</input>
{[5,4,3],[2]}
3> <input>queue:to_list(Queue1).</input>
[2,3,4,5]</pre>
      </desc>
    </func>

    <func>
      <name name="drop_r" arity="1" since=""/>
      <fsummary>Remove the rear item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the rear item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>Queue = queue:drop_r(Queue).</input>
{[4,3],[1,2]}
3> <input>queue:to_list(Queue1).</input>
[1,2,3,4]</pre>
      </desc>
    </func>

    <func>
      <name name="get" arity="1" since=""/>
      <fsummary>Return the front item of a queue.</fsummary>
      <desc>
        <p>Returns <c><anno>Item</anno></c> at the front of queue
          <c><anno>Q</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>1 == queue:get(Queue).</input>
true</pre>
      </desc>
    </func>

    <func>
      <name name="get_r" arity="1" since=""/>
      <fsummary>Return the rear item of a queue.</fsummary>
      <desc>
        <p>Returns <c><anno>Item</anno></c> at the rear of queue
          <c><anno>Q</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
2> <input>5 == queue:get_r(Queue).</input>
true</pre>
      </desc>
    </func>

    <func>
      <name name="peek" arity="1" since=""/>
      <fsummary>Return the front item of a queue.</fsummary>
      <desc>
        <p>Returns tuple <c>{value, <anno>Item</anno>}</c>, where
          <c><anno>Item</anno></c> is the front item of <c><anno>Q</anno></c>,
          or <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>queue:peek(queue:new()).</input>
empty
2> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
3> <input>queue:peek(Queue).</input>
{value, 1}</pre>
      </desc>
    </func>

    <func>
      <name name="peek_r" arity="1" since=""/>
      <fsummary>Return the rear item of a queue.</fsummary>
      <desc>
        <p>Returns tuple <c>{value, <anno>Item</anno>}</c>, where
          <c><anno>Item</anno></c> is the rear item of <c><anno>Q</anno></c>,
          or <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>queue:peek_r(queue:new()).</input>
empty
2> <input>Queue = queue:from_list([1,2,3,4,5]).</input>
{[5,4,3],[1,2]}
3> <input>queue:peek_r(Queue).</input>
{value, 5}</pre>
      </desc>
    </func>
  </funcs>

  <funcs>
    <fsdescription>
      <title>Okasaki API</title>
    </fsdescription>
    <func>
      <name name="cons" arity="2" since=""/>
      <fsummary>Insert an item at the head of a queue.</fsummary>
      <desc>
        <p>Inserts <c><anno>Item</anno></c> at the head of queue
          <c><anno>Q1</anno></c>. Returns
          the new queue <c><anno>Q2</anno></c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:cons(0, queue:from_list([1,2,3])).</input>
{[3,2],[0,1]}
2> <input>queue:to_list(Queue).</input>
[0,1,2,3]</pre>
      </desc>
    </func>

    <func>
      <name name="daeh" arity="1" since=""/>
      <fsummary>Return the tail item of a queue.</fsummary>
      <desc>
        <p>Returns the tail item of queue <c><anno>Q</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>queue:daeh(queue:from_list([1,2,3])).</input>
3</pre>
      </desc>
    </func>

    <func>
      <name name="head" arity="1" since=""/>
      <fsummary>Return the item at the head of a queue.</fsummary>
      <desc>
        <p>Returns <c><anno>Item</anno></c> from the head of queue
          <c><anno>Q</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example 1:</em></p>
          <pre>
1> <input>queue:head(queue:from_list([1,2,3])).</input>
1</pre>
      </desc>
    </func>

    <func>
      <name name="init" arity="1" since=""/>
      <fsummary>Remove the tail item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the tail item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:init(queue:from_list([1,2,3])).</input>
{[2],[1]}
2> <input>queue:to_list(Queue).</input>
[1,2]</pre>
      </desc>
    </func>

    <func>
      <name name="lait" arity="1" since=""/>
      <fsummary>Remove the tail item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the tail item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
        <p>The name <c>lait/1</c> is a misspelling - do not use it anymore.</p>
      </desc>
    </func>

    <func>
      <name name="last" arity="1" since=""/>
      <fsummary>Return the tail item of a queue.</fsummary>
      <desc>
        <p>Returns the tail item of queue <c><anno>Q</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q</anno></c> is empty.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>queue:last(queue:from_list([1,2,3])).</input>
3</pre>
      </desc>
    </func>

    <func>
      <name name="liat" arity="1" since=""/>
      <fsummary>Remove the tail item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the tail item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:liat(queue:from_list([1,2,3])).</input>
{[2],[1]}
2> <input>queue:to_list(Queue).</input>
[1,2]</pre>
      </desc>
    </func>

    <func>
      <name name="snoc" arity="2" since=""/>
      <fsummary>Insert an item at the tail of a queue.</fsummary>
      <desc>
        <p>Inserts <c><anno>Item</anno></c> as the tail item of queue
          <c><anno>Q1</anno></c>. Returns
          the new queue <c><anno>Q2</anno></c>.</p>
          <p><em>Example:</em></p>
          <pre>
1> <input>Queue = queue:snoc(queue:from_list([1,2,3]), 4).</input>
{[4,3,2],[1]}
2> <input>queue:to_list(Queue).</input>
[1,2,3,4]</pre>
      </desc>
    </func>

    <func>
      <name name="tail" arity="1" since=""/>
      <fsummary>Remove the head item from a queue.</fsummary>
      <desc>
        <p>Returns a queue <c><anno>Q2</anno></c> that is the result of removing
          the head item from <c><anno>Q1</anno></c>.</p>
        <p>Fails with reason <c>empty</c> if <c><anno>Q1</anno></c> is empty.</p>
      </desc>
    </func>
  </funcs>
</erlref>