diff --git a/lib/qex.ex b/lib/qex.ex index 011736e..84e8889 100644 --- a/lib/qex.ex +++ b/lib/qex.ex @@ -193,7 +193,7 @@ defmodule Qex do 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) @@ -224,7 +224,7 @@ defmodule Qex do 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) @@ -237,4 +237,17 @@ defmodule Qex do :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