Skip to content

Commit

Permalink
Result2 Def1 & Def2 are two separated now
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Mar 9, 2024
1 parent abdb34e commit 1b8c72d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions try/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,22 @@ func (o *Result1[T]) Def1(v T) *Result1[T] {
return o
}

// Def2 sets default value for Result.Val2. The value is returned in case of
// Def1 sets default value for Result.Val1. The value is returned in case of
// Result.Err != nil.
func (o *Result2[T, U]) Def2(v T, v2 U) *Result2[T, U] {
func (o *Result2[T, U]) Def1(v T) *Result2[T, U] {
if o.Err == nil {
return o
}
o.Val1 = v
return o
}

// Def2 sets default value for Result.Val2. The value is returned in case of
// Result.Err != nil.
func (o *Result2[T, U]) Def2(v2 U) *Result2[T, U] {
if o.Err == nil {
return o
}
o.Val2 = v2
return o
}
Expand Down
2 changes: 1 addition & 1 deletion try/result2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ExampleResult2_Logf() {
err2.SetLogTracer(os.Stdout)

countSomething := func(s1, s2 string) (int, int) {
r := try.Out2(convTwoStr(s1, s2)).Logf().Def2(10, 10)
r := try.Out2(convTwoStr(s1, s2)).Logf().Def1(10).Def2(10)
v1, v2 := r.Val1, r.Val2
return v1 + v2, v2
}
Expand Down

0 comments on commit 1b8c72d

Please sign in to comment.