-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathdo_example_test.go
More file actions
44 lines (37 loc) · 672 Bytes
/
do_example_test.go
File metadata and controls
44 lines (37 loc) · 672 Bytes
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
package mo
import (
"errors"
"fmt"
)
func ExampleDo() {
a := Ok("Hello, World!")
b := Some("42")
result := Do(func() []string {
return []string{
a.MustGet(),
b.MustGet(),
}
})
fmt.Println(result.IsError())
fmt.Println(result.MustGet())
// Output:
// false
// [Hello, World! 42]
}
func ExampleDo_panic() {
a := Ok("Hello, World!")
b := Some("42")
c := Err[string](errors.New("result error"))
result := Do(func() []string {
return []string{
a.MustGet(),
b.MustGet(),
c.MustGet(), // would panic without Do-notation
}
})
fmt.Println(result.IsError())
fmt.Println(result.Error().Error())
// Output:
// true
// result error
}