File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,70 @@ import (
99 "github.com/BooleanCat/go-functional/result"
1010)
1111
12+ func ExampleResult_Unwrap () {
13+ fmt .Println (result .Ok (4 ).Unwrap ())
14+ // Output: 4
15+ }
16+
17+ func ExampleResult_UnwrapOr () {
18+ fmt .Println (result .Ok (4 ).UnwrapOr (3 ))
19+ fmt .Println (result.Err [int ](errors .New ("oops" )).UnwrapOr (3 ))
20+ // Output:
21+ // 4
22+ // 3
23+ }
24+
25+ func ExampleResult_UnwrapOrElse () {
26+ fmt .Println (result .Ok (4 ).UnwrapOrElse (func () int {
27+ return 3
28+ }))
29+
30+ fmt .Println (result.Err [int ](errors .New ("oops" )).UnwrapOrElse (func () int {
31+ return 3
32+ }))
33+
34+ // Output:
35+ // 4
36+ // 3
37+ }
38+
39+ func ExampleResult_UnwrapOrZero () {
40+ fmt .Println (result .Ok (4 ).UnwrapOrZero ())
41+ fmt .Println (result.Err [int ](errors .New ("oops" )).UnwrapOrZero ())
42+
43+ // Output
44+ // 4
45+ // 0
46+ }
47+
48+ func ExampleResult_IsOk () {
49+ fmt .Println (result .Ok (4 ).IsOk ())
50+ fmt .Println (result.Err [int ](errors .New ("oops" )).IsOk ())
51+
52+ // Output:
53+ // true
54+ // false
55+ }
56+
57+ func ExampleResult_IsErr () {
58+ fmt .Println (result .Ok (4 ).IsErr ())
59+ fmt .Println (result.Err [int ](errors .New ("oops" )).IsErr ())
60+
61+ // Output:
62+ // false
63+ // true
64+ }
65+
66+ func ExampleResult_Value () {
67+ value , ok := result .Ok (4 ).Value ()
68+ fmt .Println (value )
69+ fmt .Println (ok )
70+
71+ // Output:
72+ // 4
73+ // <nil>
74+ }
75+
1276func TestOkStringer (t * testing.T ) {
1377 assert .Equal (t , fmt .Sprintf ("%s" , result .Ok (42 )), "Ok(42)" )
1478}
You can’t perform that action at this time.
0 commit comments