Add convenience method to create a ResultAsync from Result
See original GitHub issueIn non-Result(neverthrow)-land, using vanilla Promise
we can easily convert a non-async method to be async
using Promise.resolve('myString)
which returns Promise<string>
.
What is the equivalence using ResultAsync
? I.e. I want to super easily convert a Result<T, E>
to ResultAsync<T, E>
.
I’ve managed to do it using this code - but feels like there must be (or should be) an easier way:
export const resultToAsync = <T, E>(
result: Result<T, E>,
): ResultAsync<T, E> => {
return result.asyncAndThen((value) => {
return okAsync(value)
})
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
AsyncThrowingStream | Apple Developer Documentation
AsyncThrowingStream conforms to AsyncSequence , providing a convenient way to create an asynchronous sequence without manually implementing an asynchronous ...
Read more >Neverthrow - npm.io
errAsync convenience function to create a ResultAsync containing an Err type Result. import { ok, Ok, err, Err, Result, ...
Read more >Best way to insert a method into a class with a bound variable
What I'm trying to build apart is the method "apply(tr:scala.util.Try)". This method can call the promise "result$async" to give the result of the ......
Read more >c# - Converting convenience methods that use Tasks
You're trying to avoid making that "convenience method" async , but there's no reason to do that. What you want is to call...
Read more >Ruby | Hypertable - Big Data. Big Performance
The following code snippets illustrate how to create a Thrift client object ... The following is example output produced by the above code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Sajjon what about using
asyncMap
?In fact, there’s no need to have a
resultToAsync
function at all:Lastly, you could also use
asyncAndThen
on the result to simultaneously:Result
into aResultAsync
.Not sure, just trying to find simple solutions for @Sajjon.
Going to close this issue.