Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/qex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@spec new([term] | Range.t()) :: t
def new(init_data \\ [])

def new(x..y) do

Check warning on line 45 in lib/qex.ex

View workflow job for this annotation

GitHub Actions / test / test (1.18, 27.x)

x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it

Check warning on line 45 in lib/qex.ex

View workflow job for this annotation

GitHub Actions / test / test (1.17, 27.x)

x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it

Check warning on line 45 in lib/qex.ex

View workflow job for this annotation

GitHub Actions / test / test (1.17, 26.x)

x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it

Check warning on line 45 in lib/qex.ex

View workflow job for this annotation

GitHub Actions / test / test (1.18, 26.x)

x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it

Check warning on line 45 in lib/qex.ex

View workflow job for this annotation

GitHub Actions / test / test (1.19, 28.x, lint)

x..y inside match is deprecated, you must always match on the step: x..y//var or x..y//_ if you want to ignore it
%__MODULE__{data: :queue.from_list(Enum.to_list(x..y))}
end

Expand Down Expand Up @@ -193,7 +193,7 @@
end

@doc """
Retun the first item in the queue, raise if it's empty
Return the first item in the queue, raise if it's empty

iex> q1 = Qex.new 1..3
iex> Qex.first!(q1)
Expand Down Expand Up @@ -224,7 +224,7 @@
end

@doc """
Retun the last item in the queue, raise if it's empty
Return the last item in the queue, raise if it's empty

iex> q1 = Qex.new 1..3
iex> Qex.last!(q1)
Expand All @@ -237,4 +237,17 @@
:empty -> raise "Queue is empty"
end
end

@doc """
Return the number of elements in the queue.
This operation takes linear time.

iex> q1 = Qex.new 1..3
iex> Qex.len(q1)
3
"""
@spec len(t) :: non_neg_integer
def len(%__MODULE__{data: q}) do
:queue.len(q)
end
end