From 8c5a1da0931f7bc2de94a7649767f673b7451259 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 6 Jul 2023 15:34:57 +0200 Subject: [PATCH] Removed an allocation --- Collection.go | 2 +- README.md | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Collection.go b/Collection.go index 8271d33..94c87e9 100644 --- a/Collection.go +++ b/Collection.go @@ -27,7 +27,7 @@ type collection[T any] struct { // New creates a new collection with the given name. func New[T any](directories ...string) (*collection[T], error) { - name := reflect.TypeOf(*new(T)).Name() + name := reflect.TypeOf((*T)(nil)).Elem().Name() home, err := os.UserHomeDir() if err != nil { diff --git a/README.md b/README.md index 986c40e..b9b22cc 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,19 @@ If you like, you can operate on your entire data with classic UNIX tools. go get git.akyoto.dev/go/ocean ``` +## API + +```go +type Collection[T any] interface { + All() <-chan *T + Clear() + Delete(key string) + Exists(key string) bool + Get(key string) (value *T, ok bool) + Set(key string, value *T) +} +``` + ## Example ```go