@@ -30,27 +30,22 @@ func divide(x int, y int) (int, error) {
3030
3131func doDivide (x int , y int ) (res Result [int ]) {
3232 defer EscapeHatch (& res )
33- res = NewResult (divide (x , y )).ReturnIfErr ()
34- return res
33+ return NewResult (divide (x , y ))
3534}
3635
3736func doDivideMultiple (x int , y int ) (res Result [int ]) {
3837 defer EscapeHatch (& res )
39- res = NewResult (divide (x , y )).ReturnIfErr ()
40- res = NewResult (divide (x * 2 , y + 2 )).ReturnIfErr ()
41- return res
38+ val := NewResult (divide (x , y )).Eh ()
39+ return NewResult (divide (val + 2 , y ))
4240}
4341
4442func doDivideGoRoutine (x int , y int , res * Result [int ], wg * sync.WaitGroup ) {
4543 defer wg .Done ()
46- defer EscapeHatch (res )
47- * res = NewResult (divide (x , y )).ReturnIfErr ()
44+ * res = NewResult (divide (x , y ))
4845}
4946
50- func doDividePtr (x int , y int ) (res * Result [int ]) {
51- defer EscapeHatch (res )
52- ares := NewResult (divide (x , y )).ReturnIfErr ()
53- return & ares
47+ func doDividePtr (x int , y int ) (res Result [int ]) {
48+ return NewResult (divide (x , y ))
5449}
5550
5651func TestSimple (t * testing.T ) {
@@ -131,8 +126,8 @@ func TestSimpleResultMultipleFail(t *testing.T) {
131126func example (aFile string ) (res Result [[]byte ]) {
132127 defer EscapeHatch (& res )
133128 buff := make ([]byte , 5 )
134- file := NewResult (os .Open (aFile )).ReturnIfErr (). Ok
135- NewResult (file .Read (buff )).ReturnIfErr ()
129+ file := NewResult (os .Open (aFile )).Eh ()
130+ _ = NewResult (file .Read (buff )).Eh ()
136131 return Result [[]byte ]{Ok : buff }
137132}
138133
@@ -150,33 +145,33 @@ func TestExampleFail(t *testing.T) {
150145 }
151146}
152147
153- func TestUnwrap (t * testing.T ) {
148+ func TestMustUnwrap (t * testing.T ) {
154149 res := Result [int ]{Ok : 1 }
155- ok := res .Unwrap ()
150+ ok := res .MustUnwrap ()
156151 if ok != 1 {
157152 t .Fatal ("Unwrap should return 1" )
158153 }
159154}
160155
161- func TestUnwrapPanic (t * testing.T ) {
156+ func TestMustUnwrapPanic (t * testing.T ) {
162157 res := Result [int ]{Err : fmt .Errorf ("error" )}
163158 defer func () { recover () }()
164- _ = res .Unwrap ()
159+ _ = res .MustUnwrap ()
165160 t .Fatal ("code should have panicked" )
166161}
167162
168- func TestUnwrapErr (t * testing.T ) {
163+ func TestMustUnwrapErr (t * testing.T ) {
169164 aErr := fmt .Errorf ("error" )
170165 res := Result [int ]{Err : aErr }
171- err := res .UnwrapErr ()
166+ err := res .MustUnwrapErr ()
172167 if err != aErr {
173168 t .Fatal ("UnwrapErr should return error" )
174169 }
175170}
176171
177- func TestUnwrapErrPanic (t * testing.T ) {
172+ func TestMustUnwrapErrPanic (t * testing.T ) {
178173 res := Result [int ]{Ok : 1 }
179174 defer func () { recover () }()
180- _ = res .UnwrapErr ()
175+ _ = res .MustUnwrapErr ()
181176 t .Fatal ("code should have panicked" )
182177}
0 commit comments