This repository was archived by the owner on Aug 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_get_example_test.go
More file actions
80 lines (66 loc) · 1.83 KB
/
4_get_example_test.go
File metadata and controls
80 lines (66 loc) · 1.83 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
package mu_test
import (
"errors"
"fmt"
"github.com/appthrust/mu"
)
func ExampleEither_Left() {
// Left with Left value
left := mu.Left[string, int]("error message")
leftOpt := left.Left()
fmt.Println("Left(\"error message\").Left():", leftOpt.IsSome())
fmt.Println("Value:", leftOpt.OrZero())
// Left with Right value
right := mu.Right[string, int](42)
leftOpt2 := right.Left()
fmt.Println("Right(42).Left():", leftOpt2.IsNone())
// Output:
// Left("error message").Left(): true
// Value: error message
// Right(42).Left(): true
}
func ExampleEither_Right() {
// Right with Right value
right := mu.Right[string, int](42)
rightOpt := right.Right()
fmt.Println("Right(42).Right():", rightOpt.IsSome())
fmt.Println("Value:", rightOpt.OrZero())
// Right with Left value
left := mu.Left[string, int]("error")
rightOpt2 := left.Right()
fmt.Println("Left(\"error\").Right():", rightOpt2.IsNone())
// Output:
// Right(42).Right(): true
// Value: 42
// Left("error").Right(): true
}
func ExampleResult_Value() {
// Value with Ok
ok := mu.Ok(42)
valueOpt := ok.Value()
fmt.Println("Ok(42).Value():", valueOpt.IsSome())
fmt.Println("Value:", valueOpt.OrZero())
// Value with Err
err := mu.Err[int](errors.New("something went wrong"))
valueOpt2 := err.Value()
fmt.Println("Err.Value():", valueOpt2.IsNone())
// Output:
// Ok(42).Value(): true
// Value: 42
// Err.Value(): true
}
func ExampleResult_Error() {
// Error with Err
err := mu.Err[int](errors.New("something went wrong"))
errorOpt := err.Error()
fmt.Println("Err.Error():", errorOpt.IsSome())
fmt.Println("Error message:", errorOpt.OrZero().Error())
// Error with Ok
ok := mu.Ok(42)
errorOpt2 := ok.Error()
fmt.Println("Ok(42).Error():", errorOpt2.IsNone())
// Output:
// Err.Error(): true
// Error message: something went wrong
// Ok(42).Error(): true
}