@@ -8,6 +8,70 @@ import (
88 "github.com/BooleanCat/go-functional/option"
99)
1010
11+ func ExampleOption_Unwrap () {
12+ fmt .Println (option .Some (4 ).Unwrap ())
13+ // Output: 4
14+ }
15+
16+ func ExampleOption_UnwrapOr () {
17+ fmt .Println (option .Some (4 ).UnwrapOr (3 ))
18+ fmt .Println (option .None [int ]().UnwrapOr (3 ))
19+ // Output:
20+ // 4
21+ // 3
22+ }
23+
24+ func ExampleOption_UnwrapOrElse () {
25+ fmt .Println (option .Some (4 ).UnwrapOrElse (func () int {
26+ return 3
27+ }))
28+
29+ fmt .Println (option .None [int ]().UnwrapOrElse (func () int {
30+ return 3
31+ }))
32+
33+ // Output:
34+ // 4
35+ // 3
36+ }
37+
38+ func ExampleOption_UnwrapOrZero () {
39+ fmt .Println (option .Some (4 ).UnwrapOrZero ())
40+ fmt .Println (option .None [int ]().UnwrapOrZero ())
41+
42+ // Output
43+ // 4
44+ // 0
45+ }
46+
47+ func ExampleOption_IsSome () {
48+ fmt .Println (option .Some (4 ).IsSome ())
49+ fmt .Println (option .None [int ]().IsSome ())
50+
51+ // Output:
52+ // true
53+ // false
54+ }
55+
56+ func ExampleOption_IsNone () {
57+ fmt .Println (option .Some (4 ).IsNone ())
58+ fmt .Println (option .None [int ]().IsNone ())
59+
60+ // Output:
61+ // false
62+ // true
63+ }
64+
65+ func ExampleOption_Value () {
66+ value , ok := option .Some (4 ).Value ()
67+ fmt .Println (value )
68+ fmt .Println (ok )
69+
70+ // Output:
71+ // 4
72+ // true
73+ }
74+
1175func TestSomeStringer (t * testing.T ) {
1276 assert .Equal (t , fmt .Sprintf ("%s" , option .Some ("foo" )), "Some(foo)" )
1377 assert .Equal (t , fmt .Sprintf ("%s" , option .Some (42 )), "Some(42)" )
0 commit comments