Skip to content

Commit 13e3326

Browse files
committed
Add reminder about Enumerable and Collectable
1 parent 55fe9a3 commit 13e3326

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/circular_buffer.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ defmodule CircularBuffer do
1717
CircularBuffers are implemented as Okasaki queues like Erlang's `:queue`
1818
module, but with additional optimizations thanks to the reduced set
1919
of operations.
20+
21+
CircularBuffer implements both the
22+
[`Enumerable`](https://hexdocs.pm/elixir/Enumerable.html) and
23+
[`Collectable`](https://hexdocs.pm/elixir/Collectable.html) protocols, so code
24+
like the following works:
25+
26+
iex> cb = Enum.into([1, 2, 3, 4], CircularBuffer.new(3))
27+
#CircularBuffer<[2, 3, 4]>
28+
iex> Enum.map(cb, fn x -> x * 2 end)
29+
[4, 6, 8]
2030
"""
2131

2232
defstruct [:a, :b, :max_size, :count]

0 commit comments

Comments
 (0)