From a981a1656415c20c203f6c01bff9981542904aff Mon Sep 17 00:00:00 2001 From: Cuong Tran Date: Sat, 22 Jun 2024 12:55:52 +0700 Subject: [PATCH 1/4] chore: support variadic modifiable --- modifiable.go | 9 ++++++--- submodule_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/modifiable.go b/modifiable.go index 4b144b6..c6c0e9c 100644 --- a/modifiable.go +++ b/modifiable.go @@ -7,7 +7,7 @@ import "reflect" // That'll help the submodule to be way easier to reconfigure (for example, sharing loggers) without missing the default settings type ModifiableSubmodule[T any] interface { Submodule[T] - Append(submodule Retrievable) + Append(submodule ...Retrievable) Reset() } @@ -60,8 +60,11 @@ func (m *modifiableSubmodule[T]) retrieve(s Scope) (any, error) { return m.submodule.retrieve(s) } -func (m *modifiableSubmodule[T]) Append(submodule Retrievable) { - m.modifiers = append(m.modifiers, submodule) +func (m *modifiableSubmodule[T]) Append(submodule ...Retrievable) { + if len(submodule) == 0 { + return + } + m.modifiers = append(m.modifiers, submodule...) } func (m *modifiableSubmodule[T]) Reset() { diff --git a/submodule_test.go b/submodule_test.go index c825c53..b88ce15 100644 --- a/submodule_test.go +++ b/submodule_test.go @@ -330,7 +330,33 @@ func TestModuleFunction(t *testing.T) { require.Nil(t, e) require.Equal(t, 8, z) }) + t.Run("use variadic modifiable submodule", func(t *testing.T) { + type ( + num1 int + num2 int + ) + x := submodule.Value[num1](0) + y := submodule.Value[num2](0) + s := submodule.CreateScope() + + type nums struct { + x num1 + y num2 + } + + m := submodule.MakeModifiable[nums](func(x num1, y num2) nums { + return nums{x, y} + }, x, y) + + m.Append( + submodule.Value[num1](1), + submodule.Value[num2](2), + ) + rs, e := m.SafeResolveWith(s) + require.Nil(t, e) + require.Equal(t, nums{1, 2}, rs) + }) } type Counter struct { From dde25b5004f4f688470f51a39dff2e7480779723 Mon Sep 17 00:00:00 2001 From: Cuong Tran Date: Sat, 22 Jun 2024 12:59:24 +0700 Subject: [PATCH 2/4] chore: github action --- .github/workflows/go-test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/go-test.yml diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..8f85a41 --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,28 @@ +name: Go Test + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Install dependencies + run: go mod tidy + + - name: Run tests + run: go test ./... -v From 8a1794e76395ff8a59449524438a98fa55f8b7f8 Mon Sep 17 00:00:00 2001 From: Cuong Tran Date: Sat, 22 Jun 2024 12:59:45 +0700 Subject: [PATCH 3/4] chore: github action --- .github/workflows/go-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 8f85a41..683f3d5 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: 1.22 - name: Install dependencies run: go mod tidy From fb922c6edf1271cd9e524cbb7404a47937040bb1 Mon Sep 17 00:00:00 2001 From: Cuong Tran Date: Sat, 22 Jun 2024 13:06:58 +0700 Subject: [PATCH 4/4] chore: go test badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7624a10..f9ed010 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Managing dependency with Submodule +![Go Test](https://github.com/submodule-org/submodule.go/actions/workflows/go-test.yml/badge.svg) ![common case](common-case.png "Common case") Does the demonstrated diagram look familiar to you? A lot of applications will look just like so.