We can implement a queue using Tarsana and the built-in functions for list operations. We will use the array for queue representation as well using this code:
require __DIR__ . '/vendor/autoload.php';
use Tarsana\Functional as F;
$queue = [];
$enqueue = F\append(F\__(), F\__());
$head = F\head(F\__());
$dequeue = F\tail(F\__());
$queue = $enqueue(1, $queue);
$queue = $enqueue(2, $queue);
$queue = $enqueue(3, $queue);
echo "Queue is ".F\toString($queue)."\n";
$item = $head($queue);
$queue = $dequeue($queue);
echo "Dequeue-ed item: ".$item."\n";
echo "Queue is ".F\toString($queue)."\n";
$queue = $enqueue(4, $queue);
echo "Queue is ".F\toString($queue)."\n";
Here, we use the append function to perform enqueue, and the head and tail functions for the first item in the queue...