Would it be possible to add Result[T] return signature in functions result.Match and result.MapErr or new similar methods?
I was playing around with error handling:
res := mo.TupleToResult(dateparse.ParseAny(dateStr))
if res.IsError() {
return mo.Err[int](fmt.Errorf("dateparse could not identify format for '%s': %w", dateStr, res.Error()))
}
return mo.Ok(int(res.MustGet().Month()))
And thought
return mo.TupleToResult(dateparse.ParseAny(dateStr))
.Match(
func(t time.Time) { return mo.Ok(int(t.Month())) },
func(err error) {
return mo.Err[int](fmt.Errorf("dateparse could not identify format for '%s': %w", dateStr, res.Error()))
},
)
Or
return mo.TupleToResult(dateparse.ParseAny(dateStr))
.MapErr(func(err error) {
return mo.Err[int](fmt.Errorf("dateparse could not identify format for '%s': %w", dateStr, res.Error()))
})
.MapValue(func(t time.Time) { return int(t.Month()) })
Would be nice.
Based on the implementation, it would just be remove TupleToResult wrapper.
Would it be possible to add Result[T] return signature in functions result.Match and result.MapErr or new similar methods?
I was playing around with error handling:
And thought
Or
Would be nice.
Based on the implementation, it would just be remove TupleToResult wrapper.