-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
25 lines (23 loc) · 848 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import mapValues from "@unction/mapvalues";
import objectFrom from "@unction/objectfrom";
import pipe from "@unction/pipe";
import get from "@unction/get";
import {has} from "ramda";
import rejectByValue from "@unction/rejectbyvalue";
import thenCatchP from "@unction/thencatchp";
import thenP from "@unction/thenp";
import allP from "@unction/allp";
const asResolved = objectFrom(["resolved"]);
const asRejected = objectFrom(["rejected"]);
const onlyResolved = rejectByValue(has("rejected"));
const resolvedValues = mapValues(get("resolved"));
const onlyResolvedValues = pipe([onlyResolved, resolvedValues]);
export default function optimisticP<A> (promises: ListType<Promise<A>>): Promise<Array<A> | Set<A>> {
return pipe([
mapValues(thenCatchP(asResolved)(asRejected)),
allP,
thenP(onlyResolvedValues),
])(
promises
);
}