We could build a new container class to do FIFO pretty easily, but Arrays already do everything needed by a FIFO queue, so it is easier to just compose a Role on the existing Array class.
role FIFO { method enqueue ( *@values ) { # Add values to queue, returns the number of values added. self.push: @values;return @values.elems; } method dequeue ( ) { # Remove and return the first value from the queue.# Return Nil if queue is empty.return self.elems ?? self.shift !! Nil; } method is-empty ( ) { # Check to see if queue is empty. Returns Boolean value.return self.elems == 0; }}# Example usage:my @queue does FIFO;say @queue.is-empty; # -> Bool::Truefor <A B C> -> $i { say @queue.enqueue: $i } # 1 \n 1 \n 1say @queue.enqueue: Any; # -> 1say @queue.enqueue: 7, 8; # -> 2say @queue.is-empty; # -> Bool::Falsesay @queue.dequeue; # -> Asay @queue.elems; # -> 4say @queue.dequeue; # -> Bsay @queue.is-empty; # -> Bool::Falsesay @queue.enqueue('OHAI!'); # -> 1say @queue.dequeue until @queue.is-empty; # -> C \n Any() \n [7 8] \n OHAI!say @queue.is-empty; # -> Bool::Truesay @queue.dequeue; # ->