Skip to content

Commit f71be1b

Browse files
nabijaczleweliprincemaple
authored andcommitted
Add Qex.len(), forwarding to :queue.len()
Sponsored-by: https://beaverlabs.net
1 parent f212b68 commit f71be1b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/qex.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,17 @@ defmodule Qex do
237237
:empty -> raise "Queue is empty"
238238
end
239239
end
240+
241+
@doc """
242+
Return the number of elements in the queue.
243+
This operation takes linear time.
244+
245+
iex> q1 = Qex.new 1..3
246+
iex> Qex.len(q1)
247+
3
248+
"""
249+
@spec len(t) :: non_neg_integer
250+
def len(%__MODULE__{data: q}) do
251+
:queue.len(q)
252+
end
240253
end

0 commit comments

Comments
 (0)