diff --git a/extensions/collection.go b/extensions/collection.go index 0cf624e..28a7099 100644 --- a/extensions/collection.go +++ b/extensions/collection.go @@ -134,6 +134,15 @@ func (o *Collection[P, I]) RegisterExtensions(exts Map) error { o.valueExtensions.Set(exts) + for i := 0; i < len(o.Values); i++ { + var vi I = &o.Values[i] + if vi.GetExtensions() == nil { + if err := vi.RegisterExtensions(exts); err != nil { + return fmt.Errorf("error at index %d: %w", i, err) + } + } + } + return nil } diff --git a/extensions/collection_test.go b/extensions/collection_test.go index 95f0de7..f886934 100644 --- a/extensions/collection_test.go +++ b/extensions/collection_test.go @@ -170,6 +170,18 @@ func Test_Collection_GetExtensions(t *testing.T) { assert.NotNil(t, c.GetExtensions()) } +func Test_Collection_RegisterExtensions(t *testing.T) { + c := NewCollection[testExtensible]() + + e := testExtensible{} + c.Add(&e) + + err := c.RegisterExtensions(Map{testPoint: &testExtensions{}}) + require.NoError(t, err) + + assert.NotNil(t, c.Values[0].GetExtensions()) +} + func Test_Map(t *testing.T) { m := NewMap() assert.Equal(t, 0, len(m))