Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This one's a bit beefier than the PRs I've been posting so far. There are a few pieces here that could be accepted or rejected separately, but they all seemed to go together, so I went for the whole thing. Let me know if you'd like me to split this up or resubmit with other changes.
The main goal here was to use
R.pipedAsync
. First, I had a function which returned a constructedPromise
, which wasn't supported. Then, I noticed that the types forR.pipedAsync
(as well asR.composeAsync
andR.pipeAsync
) weren't really checking types the way their synchronous equivalents were: they were just accepting a type parameter to assert at the end of the chain. While I was in there, I simplified the functions in terms of one another, but they can work just as well in a more explicit form if you prefer it that way.There are two minor breaking changes, as described below. One is likely not to come up; the other is easy to adjust code for.
R.pipedAsync
works withnew Promise()
: I've madeR.pipedAsync
await
every returned value, so it doesn't need to inspect the function's.toString()
to determine if it should consider it async.await
ing a non-thenable simply returns the value, so this should be the expected behavior. (Incidentally, the docs make it sound like this issue applied toR.composeAsync
andR.pipeAsync
as well, but it didn't—maybe that was changed at some point without updating the docs?) BREAKING: Code which used nonasync
functions returning thenables will now startawait
ing those values instead of passing them on directly. This is unlikely to be something anyone has been expecting to work.R.composeAsync
,R.pipeAsync
, andR.pipedAsync
are type-validated: I've used types akin to these functions' synchronous counterparts to follow the types through the chain. (Note: It is possible to write more thorough types for composition, though it gets bulky. I'll leave you that link in case you're interested at some point.) BREAKING: As demonstrated inmapToObjectAsync-spec.ts
, the type parameter signature for these has changed, matching the shape of the synchronous versions. Unfortunately, this is likely to come up for many users of these functions, since they previously depended on this parameter for any type support. Luckily, the change is easy: client code should in many cases now be able to remove the type argument and let TS infer meaningful types, and where client code would prefer to still assert the type of the output, it can use an actual type assertion withas SomeType
at the end.R.composeAsync
andR.pipedAsync
are built onR.pipeAsync
: This simply refactors these functions so as not to re-write the looping logic in three places. No behavior should be changed.R.pipeAsync
is built onR.reduce
: Similarly, this is just a refactoring. No behavior should be changed.