From dcc7ad096b31f0d52c14095135ca98b936d16187 Mon Sep 17 00:00:00 2001 From: Shahryar Tavakkoli Date: Mon, 6 May 2024 16:29:40 +0330 Subject: [PATCH] VIP - Add join_to_list for :queue --- lib/modules/queue_assistant.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/modules/queue_assistant.ex b/lib/modules/queue_assistant.ex index 2b6898c..2dc4582 100644 --- a/lib/modules/queue_assistant.ex +++ b/lib/modules/queue_assistant.ex @@ -387,7 +387,8 @@ defmodule QueueAssistant do # [2, 3, 4, 5] ``` """ - @spec out(queue_type()) :: {:empty | {:value, any()}, queue_type()} + @dialyzer {:nowarn_function, out: 1} + @spec out(queue_type()) :: {:empty, {[], []}} | {{:value, any()}, queue_type()} def out(queue) do :queue.out(queue) end @@ -607,6 +608,15 @@ defmodule QueueAssistant do :queue.peek_r(queue) end + @doc """ + Please see `join/2` and `to_list/1`. + """ + @spec join_to_list(queue_type(), queue_type()) :: list(any()) + def join_to_list(queue, queue1) do + :queue.join(queue, queue1) + |> :queue.to_list() + end + # 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