File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1
1
import test from "ava" ;
2
- import { allAsync , sequenceAsync } from "./index" ;
2
+ import { allAsync , applyAsync , sequenceAsync } from "./index" ;
3
3
4
4
test ( "allAsync" , async t => {
5
5
const a = Promise . resolve ( 1 as const ) ;
@@ -52,3 +52,8 @@ test("sequenceAsync", async t => {
52
52
53
53
t . deepEqual ( a , [ 1 , 2 ] ) ;
54
54
} ) ;
55
+
56
+ test ( "applyAsync" , async t => {
57
+ const f = Promise . resolve ( ( a : number ) => a + 1 ) ;
58
+ t . is ( await applyAsync ( f ) ( 2 ) , 3 ) ;
59
+ } ) ;
Original file line number Diff line number Diff line change @@ -29,3 +29,9 @@ export async function sequenceAsync<T extends Iterable<() => unknown>>(
29
29
}
30
30
return result as SequenceAsync < T > ;
31
31
}
32
+
33
+ export function applyAsync < TA , TResult > (
34
+ promise : Promise < ( a : TA ) => TResult >
35
+ ) : ( a : TA ) => Promise < TResult > {
36
+ return async a => promise . then ( f => f ( a ) ) ;
37
+ }
You can’t perform that action at this time.
0 commit comments