From db40d19507b5c61347318b811bd25ed908d95aec Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Sun, 24 Aug 2025 15:14:49 -0700 Subject: [PATCH] Add New Example --- di_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/di_test.go b/di_test.go index 852b46fb77a457ca4441f0c98814c55117088234..68e54fb7bacb749e36fedca12341cae6c8266579 100644 --- a/di_test.go +++ b/di_test.go @@ -37,6 +37,32 @@ func ExampleBuild() { // Output: Hello, Alice. You've been around the sun 42 times! } +func ExampleNew() { + type Username string + type Config struct { + User Username + Age int + Greeting func(Username, int) string + } + + cfg := Config{ + User: "Alice", + Age: 42, + Greeting: func(u Username, age int) string { + return fmt.Sprintf("Hello, %s. You've been around the sun %d times!", string(u), age) + }, + } + + greeting, err := New[string](cfg) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(greeting) + + // Output: Hello, Alice. You've been around the sun 42 times! +} + func TestBuildSuccess(t *testing.T) { type A struct { val string