Commit c089c3f

mo khan <mo@mokhan.ca>
2025-07-24 18:32:51
refactor: rename ctor function
1 parent 2ea19d0
pkg/event/typed_aggregator.go
@@ -4,9 +4,13 @@ type TypedAggregator[T any] struct {
 	aggregator *Aggregator
 }
 
-func NewTypedAggregator[T any]() *TypedAggregator[T] {
+func NewAggregator[T any]() *TypedAggregator[T] {
+	return NewWith[T](New())
+}
+
+func NewWith[T any](aggregator *Aggregator) *TypedAggregator[T] {
 	return &TypedAggregator[T]{
-		aggregator: New(),
+		aggregator: aggregator,
 	}
 }
 
pkg/event/typed_aggregator_test.go
@@ -13,7 +13,7 @@ func TestTypedAggregator(t *testing.T) {
 
 	t.Run("Publish", func(t *testing.T) {
 		t.Run("without any subscribers", func(t *testing.T) {
-			aggregator := NewTypedAggregator[announcement]()
+			aggregator := NewAggregator[announcement]()
 
 			aggregator.Publish("announcement", announcement{
 				message: "Business, Business, Business... Numbers!",
@@ -22,7 +22,7 @@ func TestTypedAggregator(t *testing.T) {
 
 		t.Run("with a single subscription", func(t *testing.T) {
 			called := false
-			aggregator := NewTypedAggregator[announcement]()
+			aggregator := NewAggregator[announcement]()
 
 			aggregator.SubscribeTo("announcement", func(payload announcement) {
 				called = true
@@ -35,7 +35,7 @@ func TestTypedAggregator(t *testing.T) {
 		})
 
 		t.Run("with multiple subscribers", func(t *testing.T) {
-			aggregator := NewTypedAggregator[announcement]()
+			aggregator := NewAggregator[announcement]()
 			called := map[int]bool{}
 
 			aggregator.SubscribeTo("announcement", func(payload announcement) {