Commit 95c1a8f

mo khan <mo@mokhan.ca>
2025-07-24 18:53:26
refactor: remove New()
1 parent da928b0
pkg/event/aggregator.go
@@ -6,12 +6,6 @@ type Aggregator struct {
 	subscriptions map[Event][]Subscription
 }
 
-func New() *Aggregator {
-	return x.New[*Aggregator](
-		WithoutSubscriptions(),
-	)
-}
-
 func WithoutSubscriptions() x.Option[*Aggregator] {
 	return WithSubscriptions(map[Event][]Subscription{})
 }
pkg/event/aggregator_test.go
@@ -4,18 +4,19 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
+	"github.com/xlgmokha/x/pkg/x"
 )
 
 func TestAggregator(t *testing.T) {
 	t.Run("Publish", func(t *testing.T) {
 		t.Run("without any subscribers", func(t *testing.T) {
-			aggregator := New()
+			aggregator := x.New(WithoutSubscriptions())
 
 			aggregator.Publish("announcements.engineering", "Business, Business, Business... Numbers!")
 		})
 
 		t.Run("with a single subscriber", func(t *testing.T) {
-			aggregator := New()
+			aggregator := x.New(WithoutSubscriptions())
 			called := false
 
 			aggregator.Subscribe("announcement", func(message any) {
@@ -29,7 +30,7 @@ func TestAggregator(t *testing.T) {
 		})
 
 		t.Run("with multiple subscribers", func(t *testing.T) {
-			aggregator := New()
+			aggregator := x.New(WithoutSubscriptions())
 			called := map[int]bool{}
 
 			aggregator.Subscribe("announcement", func(message any) {
pkg/event/typed_aggregator.go
@@ -7,7 +7,13 @@ type TypedAggregator[T any] struct {
 }
 
 func NewAggregator[T any]() *TypedAggregator[T] {
-	return NewWith[T](x.New(WithoutSubscriptions()))
+	return x.New[*TypedAggregator[T]](
+		WithAggregator[T](
+			x.New(
+				WithoutSubscriptions(),
+			),
+		),
+	)
 }
 
 func NewWith[T any](aggregator *Aggregator) *TypedAggregator[T] {