TaskResultBuilder ?
games opened this issue · comments
Hi, do you plan or any idea to make a TaskResultBuilder which similar with AsyncChoiceBuilder.
type AsyncChoice<'T, 'Error> = Async<Choice<'T, 'Error>>
type AsyncChoiceBuilder () =
member __.Return x = // 'T -> M<'T>
member __.Bind m f = // M<'T> * ('T -> M<'U>) -> M<'U>
type TaskResult<'T, 'Error> = Task<Result<'T, 'Error>>
I think you can write your own pretty easily without getting into the guts of task handling, just by wrapping TaskBuilder
. For now, I recommend going that route.
e.g.
type TaskResultBuilder() =
member this.Bind
( resultTask : Result<'ok, 'err> Task
, onOk : 'ok -> Task<Result<'out, 'err>>
) : Task<'out, 'err>> =
task {
let! maybe = resultTask
match maybe with
| Ok yep -> return! onOk yep
| Error e -> return Error e
}
member this.Return(x) = Task.FromResult(Ok x)
Hi @rspeele, yes I can write my own TaskResultBuilder (I currently do it in my few projects) but just I need to copy the file to all of my projects which uses Task+Result. so just wondering if I can use any other thirth party lib instead I do myself (especially I am using your TaskBuilder) :-)
I recommend publishing your own wrapper (that you mentioned you're currently using) as a NuGet package. If you don't want it to be a big thing, you can use a local feed.