diff --git a/src/composable/composable.ts b/src/composable/composable.ts index 6b2c0e53..74637fb4 100644 --- a/src/composable/composable.ts +++ b/src/composable/composable.ts @@ -111,9 +111,9 @@ function map( ) { return (async (...args) => { const res = await fn(...args) - if(!res.success) return error(res.errors) + if (!res.success) return error(res.errors) const mapped = await composable(mapper)(res.data) - if(!mapped.success) return error(mapped.errors) + if (!mapped.success) return error(mapped.errors) return mapped }) as Composable<(...args: Parameters) => R> } @@ -135,20 +135,20 @@ function map( */ function mapError( fn: T, - mapper: (err: ErrorWithMessage) => ErrorWithMessage, + mapper: (err: Omit) => Omit, ) { return (async (...args) => { const res = await fn(...args) - return !res.success ? error(res.errors.map(mapper)) : success(res.data) + return !res.success ? error(mapper(res).errors) : success(res.data) }) as T } export { all, + collect, composable, composable as cf, composable as λ, - collect, error, map, mapError, diff --git a/src/composable/index.test.ts b/src/composable/index.test.ts index bb9f82ce..1a230519 100644 --- a/src/composable/index.test.ts +++ b/src/composable/index.test.ts @@ -1,8 +1,4 @@ -import { - assertEquals, - describe, - it, -} from '../test-prelude.ts' +import { assertEquals, describe, it } from '../test-prelude.ts' import { map, mapError, pipe, sequence } from './index.ts' import type { Composable, ErrorWithMessage, Result } from './index.ts' import { Equal, Expect } from './types.test.ts' @@ -257,10 +253,7 @@ describe('map', () => { }) it('maps over a composition', async () => { - const fn = map( - pipe(λ(add), λ(toString)), - (a) => typeof a === 'string', - ) + const fn = map(pipe(λ(add), λ(toString)), (a) => typeof a === 'string') const res = await fn(1, 2) type _FN = Expect< @@ -290,7 +283,9 @@ const cleanError = (err: ErrorWithMessage) => ({ }) describe('mapError', () => { it('maps over the error results of an Composable function', async () => { - const fn = mapError(λ(faultyAdd), cleanError) + const fn = mapError(λ(faultyAdd), ({ errors }) => ({ + errors: errors.map(cleanError), + })) const res = await fn(1, 2) type _FN = Expect<