result.take
is shift
.The point of such a proxy is to let the user choose the underling data structure behind the FIFO.
Note that some Sequence
, like Array
, have an inefficient shift
implementation,
thus are not the best candidates to serve as a FIFO.
var a = new List[Int].from([1,2,3])
var q = a.as_fifo
assert q.take == 1
q.add(4)
q.add(5)
assert q.take == 2
assert a == [3, 4, 5]
# Return a FIFO proxy queue where `result.take` is `shift`.
#
# The point of such a proxy is to let the user choose the underling data structure
# behind the FIFO.
#
# Note that some `Sequence`, like `Array`, have an inefficient `shift` implementation,
# thus are not the best candidates to serve as a FIFO.
#
# ~~~
# var a = new List[Int].from([1,2,3])
# var q = a.as_fifo
# assert q.take == 1
# q.add(4)
# q.add(5)
# assert q.take == 2
# assert a == [3, 4, 5]
# ~~~
fun as_fifo: Queue[E] do return new FifoQueue[E](self)
lib/core/queue.nit:118,2--135,55