-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_reorder_test.go
67 lines (63 loc) · 1.4 KB
/
example_reorder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package nject_test
import (
"fmt"
"github.com/muir/nject"
)
// This demonstrates how it to have a default that gets overridden by
// by later inputs using Reorder
func ExampleReorder() {
type string2 string
seq1 := nject.Sequence("example",
nject.Shun(func() string {
fmt.Println("fallback default included")
return "fallback default"
}),
func(s string) string2 {
return "<" + string2(s) + ">"
},
)
seq2 := nject.Sequence("later inputs",
// for this to work, it must be reordered to be in front
// of the string->string2 provider
nject.Reorder(func() string {
return "override value"
}),
)
fmt.Println(nject.Run("combination",
seq1,
seq2,
func(s string2) {
fmt.Println(s)
},
))
// Output: <override value>
// <nil>
}
// This demonstrates how it to have a default that gets overridden by
// by later inputs using ReplaceNamed
func ExampleReplaceNamed() {
type string2 string
seq1 := nject.Sequence("example",
nject.Provide("default-string", func() string {
fmt.Println("fallback default included")
return "fallback default"
}),
func(s string) string2 {
return "<" + string2(s) + ">"
},
)
seq2 := nject.Sequence("later inputs",
nject.ReplaceNamed("default-string", func() string {
return "override value"
}),
)
fmt.Println(nject.Run("combination",
seq1,
seq2,
func(s string2) {
fmt.Println(s)
},
))
// Output: <override value>
// <nil>
}