Skip to content

Commit

Permalink
fix example (#132)
Browse files Browse the repository at this point in the history
In a real-world usage scenario the user will be importing golang-lru, not running it in the same file. Thus we can't just do `New`, we need to do `lru.New`. While I was at it I changed the example to be a complete runnable example. 

https://replit.com/@almenon/FrenchFickleOutliers#main.go

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
  • Loading branch information
Almenon and jefferai committed Jun 6, 2023
1 parent 41616a9 commit b74c7fa
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ Example
Using the LRU is very simple:

```go
l, _ := New[int, any](128)
for i := 0; i < 256; i++ {
l.Add(i, nil)
}
if l.Len() != 128 {
panic(fmt.Sprintf("bad len: %v", l.Len()))
package main

import (
"fmt"
"github.com/hashicorp/golang-lru/v2"
)

func main() {
l, _ := lru.New[int, any](128)
for i := 0; i < 256; i++ {
l.Add(i, nil)
}
if l.Len() != 128 {
panic(fmt.Sprintf("bad len: %v", l.Len()))
}
}
```

0 comments on commit b74c7fa

Please sign in to comment.