From 4693b3e43b56efde963adaf94986d88d5bc90e0a Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Sat, 9 Mar 2024 19:04:31 -0500 Subject: [PATCH 1/2] A Composable map is a pipe where the mapper is first turned into another Composable. The code gets a bit shorter and easier to understand IMHO --- src/composable/composable.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/composable/composable.ts b/src/composable/composable.ts index 5b0fbcac..0bd3baa2 100644 --- a/src/composable/composable.ts +++ b/src/composable/composable.ts @@ -179,13 +179,9 @@ function map( fn: T, mapper: (res: UnpackResult>) => R, ) { - return (async (...args) => { - const res = await fn(...args) - if (!res.success) return error(res.errors) - const mapped = await composable(mapper)(res.data) - if (!mapped.success) return error(mapped.errors) - return mapped - }) as Composable<(...args: Parameters) => R> + return pipe(fn as Composable, composable(mapper) as Composable) as Composable< + (...args: Parameters) => R + > } /** @@ -226,4 +222,3 @@ export { sequence, success, } - From 5942b8cbeef6c13b955595ed3eb43fbbb882c4e8 Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Sat, 9 Mar 2024 19:23:38 -0500 Subject: [PATCH 2/2] Also simplify DF map implementation --- src/domain-functions.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/domain-functions.ts b/src/domain-functions.ts index b1cced6e..78d53ae0 100644 --- a/src/domain-functions.ts +++ b/src/domain-functions.ts @@ -235,13 +235,9 @@ function map( dfn: DomainFunction, mapper: (element: O) => R | Promise, ): DomainFunction { - return ((input, environment) => - dfResultFromcomposable( - A.map( - A.composable(() => fromSuccess(dfn)(input, environment)), - mapper, - ), - )()) as DomainFunction + return dfResultFromcomposable( + A.map(A.composable(fromSuccess(dfn)), mapper), + ) as DomainFunction } /**