Consider adding TryMap extension methods
Closed this issue · 4 comments
Currently, Map
functions wrap the Func<T,K>
in Result.Success(...)
This is problematic if the func
raises an exception.
Please consider adding similar methods for TryMap
ping (i.e. wrapping the func in Result.Try(...)
)
For me the proposed method sounds like a case for Bind
(i.e. Map
that potentially maps value to error is not actually Map
).
How about result.Bind(value => Result.Try(() => func(value)))
as a workaround?
For me the proposed method sounds like a case for
Bind
(i.e.Map
that potentially maps value to error is not actuallyMap
).
OK, agreed.
How about
result.Bind(value => Result.Try(() => func(value)))
as a workaround?
What about TryBind instead of TryMap to avoid Result.Try
-ing, so this
result.Bind(value => Result.Try(() => func(value)))
would be
result.TryBind(value => () => func(value))
@petrechitashvili The new extension looks good to me. But I think BindTry
is a better name here: we are binding the result of an inner Try
call, as opposed to trying (i.e. invoking a method that may throw) a Bind
method.
I'm sure the issue may be closed as implemented