Skip to content

Commit

Permalink
to_list/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgy Sychev committed Oct 16, 2023
1 parent 8b73c44 commit 0f3cfa3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/persistent_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,25 @@ defmodule PersistentQueue do
{{:value, entry}, %{queue | ins: ins, outs: outs, size: size - 1, storage: storage}}
end
end

@doc """
Converts queue to list, where the first entry is the head entry
## Example:
iex> queue = new(limit: 4, storage: %PersistentQueue.DroppingStorage{})
iex> queue =
...> queue
...> |> enqueue(1)
...> |> enqueue(2)
...> |> enqueue(3)
iex> to_list(queue)
[1, 2, 3]
"""
@spec to_list(t(entry)) :: [entry]
when entry: term()
def to_list(queue) do
{entries, _} = dequeue_n(queue, queue.size)
entries
end
end

0 comments on commit 0f3cfa3

Please sign in to comment.