Skip to content

Commit

Permalink
Implement all in terms of atmp
Browse files Browse the repository at this point in the history
  • Loading branch information
diogob committed Nov 7, 2023
1 parent a590ed9 commit eefd87d
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/domain-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,10 @@ function all<Fns extends DomainFunction[]>(
...fns: Fns
): DomainFunction<UnpackAll<Fns>> {
return ((input, environment) => {
return safeResult(async () => {
const results = await Promise.all(
fns.map((fn) => (fn as DomainFunction)(input, environment)),
)

if (results.some(({ success }) => success === false)) {
throw new ResultError({
errors: results.map(({ errors }) => errors).flat(),
inputErrors: results.map(({ inputErrors }) => inputErrors).flat(),
environmentErrors: results
.map(({ environmentErrors }) => environmentErrors)
.flat(),
})
}

return (results as SuccessResult<unknown>[]).map(({data}) => data)
})
const [first, ...rest] = fns.map((df) =>
atmp(() => fromSuccess(df)(input, environment)),
)
return dfResultFromAtmp(A.all(first, ...rest))()
}) as DomainFunction<UnpackAll<Fns>>
}

Expand Down

0 comments on commit eefd87d

Please sign in to comment.