FsToolkit.ErrorHandling
FsToolkit.ErrorHandling copied to clipboard
helper to convert option to result with transform
I may have overlooked a helper in either this or the standard library, but I end up finding this function useful, similar to requireSome but where the fallback is evaluated on demand.
let fromOption f = (unit -> 'a) -> option<'b> -> Result<'b,'a>
function
| Some value -> Ok value
| None -> Error(f ())
Is there an equivalent or would it make sense to add perhaps Result.requireSomeWith?
Agreed! Seem like a good PR to have:
- Add
requireSomeWithandrequireNoneWith - Add to
Result,AsyncResult,TaskResult,JobResult - Add corresponding tests