From 622ebf4df0fa3971687249154188ceafa56d839c Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Fri, 31 Mar 2023 15:42:37 +0700 Subject: [PATCH] style: errors, collections (#15640) --- collections/codec/bool.go | 5 ++--- collections/indexed_map.go | 10 +++++----- collections/indexes/reverse_pair.go | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/collections/codec/bool.go b/collections/codec/bool.go index b5ab8dcd93..4016c8d68d 100644 --- a/collections/codec/bool.go +++ b/collections/codec/bool.go @@ -14,10 +14,9 @@ func (b boolKey[T]) Encode(buffer []byte, key T) (int, error) { if key { buffer[0] = 0x1 return 1, nil - } else { - buffer[0] = 0x0 - return 1, nil } + buffer[0] = 0x0 + return 1, nil } func (b boolKey[T]) Decode(buffer []byte) (int, T, error) { diff --git a/collections/indexed_map.go b/collections/indexed_map.go index c761658ea4..1625c47aec 100644 --- a/collections/indexed_map.go +++ b/collections/indexed_map.go @@ -38,10 +38,10 @@ type IndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]] struct { } // NewIndexedMap instantiates a new IndexedMap. Accepts a SchemaBuilder, a Prefix, -// a humanised name that defines the name of the collection, the primary key codec +// a humanized name that defines the name of the collection, the primary key codec // which is basically what IndexedMap uses to encode the primary key to bytes, // the value codec which is what the IndexedMap uses to encode the value. -// Then it expects the initialised indexes. +// Then it expects the initialized indexes. func NewIndexedMap[PrimaryKey, Value any, Idx Indexes[PrimaryKey, Value]]( schema *SchemaBuilder, prefix Prefix, @@ -112,7 +112,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) ValueCodec() codec.ValueCodec[Value func (m *IndexedMap[PrimaryKey, Value, Idx]) ref(ctx context.Context, pk PrimaryKey, value Value) error { for _, index := range m.Indexes.IndexesList() { - err := index.Reference(ctx, pk, value, cachedGet[PrimaryKey, Value](m, ctx, pk)) + err := index.Reference(ctx, pk, value, cachedGet[PrimaryKey, Value](ctx, m, pk)) if err != nil { return err } @@ -122,7 +122,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) ref(ctx context.Context, pk Primary func (m *IndexedMap[PrimaryKey, Value, Idx]) unref(ctx context.Context, pk PrimaryKey) error { for _, index := range m.Indexes.IndexesList() { - err := index.Unreference(ctx, pk, cachedGet[PrimaryKey, Value](m, ctx, pk)) + err := index.Unreference(ctx, pk, cachedGet[PrimaryKey, Value](ctx, m, pk)) if err != nil { return err } @@ -134,7 +134,7 @@ func (m *IndexedMap[PrimaryKey, Value, Idx]) unref(ctx context.Context, pk Prima // returns always the same result on multiple calls. func cachedGet[K, V any, M interface { Get(ctx context.Context, key K) (V, error) -}](m M, ctx context.Context, key K, +}](ctx context.Context, m M, key K, ) func() (V, error) { var ( value V diff --git a/collections/indexes/reverse_pair.go b/collections/indexes/reverse_pair.go index cc846e92d9..55e4007e5f 100644 --- a/collections/indexes/reverse_pair.go +++ b/collections/indexes/reverse_pair.go @@ -26,7 +26,7 @@ type pairKeyCodec[K1, K2 any] interface { // NewReversePair instantiates a new ReversePair index. // NOTE: when using this function you will need to type hint: doing NewReversePair[Value]() // Example: if the value of the indexed map is string, you need to do NewReversePair[string](...) -func NewReversePair[Value any, K1, K2 any]( +func NewReversePair[Value, K1, K2 any]( sb *collections.SchemaBuilder, prefix collections.Prefix, name string,