Skip to content

Commit 7a684ce

Browse files
committed
Add an example to the readme
1 parent 3307c70 commit 7a684ce

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@
77

88
CircularBuffer provides a general-purpose circular buffer data structure.
99

10+
```elixir
11+
# Create a new circular buffer that holds 5 elements
12+
iex> cb = CircularBuffer.new(5)
13+
#CircularBuffer<[]>
14+
15+
# Fill it up
16+
iex> cb = Enum.into(1..5, cb)
17+
#CircularBuffer<[1, 2, 3, 4, 5]>
18+
19+
# Verify that 1 is the oldest and 5 is the newest element in the buffer
20+
iex> CircularBuffer.oldest(cb)
21+
1
22+
iex> CircularBuffer.newest(cb)
23+
5
24+
25+
# Add another element. 1 gets pushed out.
26+
iex> cb = CircularBuffer.insert(cb, 6)
27+
#CircularBuffer<[2, 3, 4, 5, 6]>
28+
29+
# CircularBuffer implements Enumerable so all Enum.* functions work
30+
iex> Enum.sum(cb)
31+
20
32+
```
33+
1034
## Installation
1135

1236
```elixir
@@ -19,7 +43,7 @@ end
1943

2044
## Should I use this?
2145

22-
The entire codebase is less than 50 lines of code and has been tested using
23-
property based testing. I believe the implementation is sound but it may not
24-
be the highest performance library out there.
25-
46+
The entire codebase is about 70 lines of code, has been tested using property
47+
based testing, and has been used in production for several years. I believe the
48+
implementation is sound but it may not be the highest performance library out
49+
there.

0 commit comments

Comments
 (0)