diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..683f3d5 --- /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.22 + + - name: Install dependencies + run: go mod tidy + + - name: Run tests + run: go test ./... -v 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. 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 {