From 843f6460ef47305f85a334d27498195cf5b51397 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 19:34:06 +0200 Subject: [PATCH 1/9] feat: flatMapIOEither --- src/ReaderTaskEither.ts | 57 ++++++++++++++++++++----------- src/StateReaderTaskEither.ts | 63 ++++++++++++++++++++++++----------- src/TaskEither.ts | 55 +++++++++++++++++++----------- test/ReaderTaskEither.ts | 4 +++ test/StateReaderTaskEither.ts | 10 ++++++ test/TaskEither.ts | 10 ++++++ 6 files changed, 141 insertions(+), 58 deletions(-) diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index 17fff55a3..4d3cd482e 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -448,26 +448,6 @@ export const fromIOEitherK = , B>( f: (...a: A) => IOEither ): ((...a: A) => ReaderTaskEither) => flow(f, fromIOEither) -/** - * Less strict version of [`chainIOEitherK`](#chainioeitherk). - * - * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. - * - * @category sequencing - * @since 2.6.1 - */ -export const chainIOEitherKW: ( - f: (a: A) => IOEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = (f) => flatMap(fromIOEitherK(f)) - -/** - * @category sequencing - * @since 2.4.0 - */ -export const chainIOEitherK: ( - f: (a: A) => IOEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = chainIOEitherKW - /** * @category lifting * @since 2.4.0 @@ -1587,6 +1567,19 @@ export const flatMapReaderIO: { flatMap(self, fromReaderIOK(f)) ) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapIOEither: { + (f: (a: A) => IOEither): (self: ReaderTaskEither) => ReaderTaskEither + (self: ReaderTaskEither, f: (a: A) => IOEither): ReaderTaskEither +} = /*#__PURE__*/ dual( + 2, + (self: ReaderTaskEither, f: (a: A) => IOEither): ReaderTaskEither => + flatMap(self, fromIOEitherK(f)) +) + /** * Alias of `flatMapEither`. * @@ -1836,6 +1829,30 @@ export const chainReaderIOK: ( f: (a: A) => ReaderIO ) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapReaderIO +/** + * Alias of `flatMapIOEither`. + * + * Less strict version of [`chainIOEitherK`](#chainioeitherk). + * + * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. + * + * @category legacy + * @since 2.6.1 + */ +export const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapIOEither + +/** + * Alias of `flatMapIOEither`. + * + * @category legacy + * @since 2.4.0 + */ +export const chainIOEitherK: ( + f: (a: A) => IOEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapIOEither + // ------------------------------------------------------------------------------------- // utils // ------------------------------------------------------------------------------------- diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index fa6fbfbc3..5ccaf4072 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -268,25 +268,6 @@ export const fromIOEitherK = (...a) => fromIOEither(f(...a)) -/** - * Less strict version of [`chainIOEitherK`](#chainioeitherk). - * - * @category sequencing - * @since 2.6.1 - */ -export const chainIOEitherKW = - (f: (a: A) => IOEither) => - (ma: StateReaderTaskEither): StateReaderTaskEither => - flatMap(ma, fromIOEitherK(f)) - -/** - * @category sequencing - * @since 2.4.0 - */ -export const chainIOEitherK: ( - f: (a: A) => IOEither -) => (ma: StateReaderTaskEither) => StateReaderTaskEither = chainIOEitherKW - /** * @category lifting * @since 2.4.0 @@ -513,6 +494,28 @@ export const flatMapReader: { > } = /*#__PURE__*/ _.flatMapReader(_FromReader, _FlatMap) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapIOEither: { + (f: (a: A) => IOEither): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => IOEither): StateReaderTaskEither< + S, + R, + E1 | E2, + B + > +} = /*#__PURE__*/ dual( + 2, + ( + self: StateReaderTaskEither, + f: (a: A) => IOEither + ): StateReaderTaskEither => flatMap(self, (a: A) => fromIOEitherK(f)(a)) +) + /** * Less strict version of [`flatten`](#flatten). * @@ -1224,6 +1227,28 @@ export const chainTaskEitherK: ( f: (a: A) => TaskEither ) => (ma: StateReaderTaskEither) => StateReaderTaskEither = flatMapTaskEither +/** + * Alias of `flatMapIOEither`. + * + * Less strict version of [`chainIOEitherK`](#chainioeitherk). + * + * @category legacy + * @since 2.6.1 + */ +export const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither = flatMapIOEither + +/** + * Alias of `flatMapIOEither`. + * + * @category legacy + * @since 2.4.0 + */ +export const chainIOEitherK: ( + f: (a: A) => IOEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither = flatMapIOEither + /** * @category lifting * @since 2.10.0 diff --git a/src/TaskEither.ts b/src/TaskEither.ts index 14337e017..212365654 100644 --- a/src/TaskEither.ts +++ b/src/TaskEither.ts @@ -425,25 +425,6 @@ export const fromIOEitherK = , B>( f: (...a: A) => IOEither ): ((...a: A) => TaskEither) => flow(f, fromIOEither) -/** - * Less strict version of [`chainIOEitherK`](#chainioeitherk). - * - * The `W` suffix (short for **W**idening) means that the error types will be merged. - * - * @category sequencing - * @since 2.6.1 - */ -export const chainIOEitherKW: ( - f: (a: A) => IOEither -) => (ma: TaskEither) => TaskEither = (f) => flatMap(fromIOEitherK(f)) - -/** - * @category sequencing - * @since 2.4.0 - */ -export const chainIOEitherK: (f: (a: A) => IOEither) => (ma: TaskEither) => TaskEither = - chainIOEitherKW - const _map: Functor2['map'] = (fa, f) => pipe(fa, map(f)) const _apPar: Apply2['ap'] = (fab, fa) => pipe(fab, ap(fa)) const _apSeq: Apply2['ap'] = (fab, fa) => flatMap(fab, (f) => pipe(fa, map(f))) @@ -1260,6 +1241,19 @@ export const flatMapTask: { (self: TaskEither, f: (a: A) => Task): TaskEither } = /*#__PURE__*/ _.flatMapTask(_FromTask, _FlatMap) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapIOEither: { + (f: (a: A) => IOEither): (self: TaskEither) => TaskEither + (self: TaskEither, f: (a: A) => IOEither): TaskEither +} = /*#__PURE__*/ dual( + 2, + (self: TaskEither, f: (a: A) => IOEither): TaskEither => + flatMap(self, fromIOEitherK(f)) +) + /** * Alias of `flatMapEither`. * @@ -1398,6 +1392,29 @@ export const chainTaskK: (f: (a: A) => T.Task) => (first: TaskEither export const chainFirstTaskK: (f: (a: A) => T.Task) => (first: TaskEither) => TaskEither = tapTask +/** + * Alias of `flatMapIOEither`. + * + * Less strict version of [`chainIOEitherK`](#chainioeitherk). + * + * The `W` suffix (short for **W**idening) means that the error types will be merged. + * + * @category legacy + * @since 2.6.1 + */ +export const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: TaskEither) => TaskEither = flatMapIOEither + +/** + * Alias of `flatMapIOEither`. + * + * @category legacy + * @since 2.4.0 + */ +export const chainIOEitherK: (f: (a: A) => IOEither) => (ma: TaskEither) => TaskEither = + flatMapIOEither + // ------------------------------------------------------------------------------------- // utils // ------------------------------------------------------------------------------------- diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts index 9739d7be2..190fd737e 100644 --- a/test/ReaderTaskEither.ts +++ b/test/ReaderTaskEither.ts @@ -823,4 +823,8 @@ describe.concurrent('ReaderTaskEither', () => { it('flatMapReaderIO', async () => { U.deepStrictEqual(await _.flatMapReaderIO(_.of(1), () => RIO.of(2))(undefined)(), E.of(2)) }) + + it('flatMapIOEither', async () => { + U.deepStrictEqual(await _.flatMapIOEither(_.of(1), () => IE.of(2))(undefined)(), E.of(2)) + }) }) diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index 8ef32e375..7238162ed 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -583,4 +583,14 @@ describe.concurrent('StateReaderTaskEither', () => { E.of(2) ) }) + + it('flatMapIOEither', async () => { + U.deepStrictEqual( + await pipe( + _.flatMapIOEither(_.of(1), () => IE.of(2)), + _.evaluate(state) + )(undefined)(), + E.of(2) + ) + }) }) diff --git a/test/TaskEither.ts b/test/TaskEither.ts index 03a71daa6..c9afb8257 100644 --- a/test/TaskEither.ts +++ b/test/TaskEither.ts @@ -896,4 +896,14 @@ describe.concurrent('TaskEither', () => { const f = (s: string) => T.of(s.length) U.deepStrictEqual(await pipe(_.of('a'), _.flatMapTask(f))(), E.of(1)) }) + + it('flatMapIOEither', async () => { + U.deepStrictEqual( + await pipe( + _.of(1), + _.flatMapIOEither(() => IE.of(2)) + )(), + E.of(2) + ) + }) }) From 6b95d35938f61f10b28445c9097b2a050111636d Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 19:38:42 +0200 Subject: [PATCH 2/9] feat: flatMapReaderEither --- src/ReaderTaskEither.ts | 66 +++++++++++++++++++++++++++------------- test/ReaderTaskEither.ts | 4 +++ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index 4d3cd482e..18b49227b 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -464,27 +464,6 @@ export const fromReaderEitherK = , B>( f: (...a: A) => ReaderEither ): ((...a: A) => ReaderTaskEither) => flow(f, fromReaderEither) -/** - * Less strict version of [`chainReaderEitherK`](#chainreadereitherk). - * - * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. - * - * @category sequencing - * @since 2.11.0 - */ -export const chainReaderEitherKW: ( - f: (a: A) => ReaderEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = (f) => - flatMap(fromReaderEitherK(f)) - -/** - * @category sequencing - * @since 2.11.0 - */ -export const chainReaderEitherK: ( - f: (a: A) => ReaderEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = chainReaderEitherKW - const _map: Functor3['map'] = (fa, f) => pipe(fa, map(f)) const _apPar: Apply3['ap'] = (fab, fa) => pipe(fab, ap(fa)) const _apSeq: Apply3['ap'] = (fab, fa) => flatMap(fab, (f) => pipe(fa, map(f))) @@ -1580,6 +1559,27 @@ export const flatMapIOEither: { flatMap(self, fromIOEitherK(f)) ) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapReaderEither: { + (f: (a: A) => ReaderEither): ( + self: ReaderTaskEither + ) => ReaderTaskEither + (self: ReaderTaskEither, f: (a: A) => ReaderEither): ReaderTaskEither< + R1 & R2, + E1 | E2, + B + > +} = /*#__PURE__*/ dual( + 2, + ( + self: ReaderTaskEither, + f: (a: A) => ReaderEither + ): ReaderTaskEither => flatMap(self, fromReaderEitherK(f)) +) + /** * Alias of `flatMapEither`. * @@ -1853,6 +1853,30 @@ export const chainIOEitherK: ( f: (a: A) => IOEither ) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapIOEither +/** + * Alias of `flatMapReaderEither`. + * + * Less strict version of [`chainReaderEitherK`](#chainreadereitherk). + * + * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. + * + * @category legacy + * @since 2.11.0 + */ +export const chainReaderEitherKW: ( + f: (a: A) => ReaderEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapReaderEither + +/** + * Alias of `flatMapReaderEither`. + * + * @category legacy + * @since 2.11.0 + */ +export const chainReaderEitherK: ( + f: (a: A) => ReaderEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = flatMapReaderEither + // ------------------------------------------------------------------------------------- // utils // ------------------------------------------------------------------------------------- diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts index 190fd737e..07d784d16 100644 --- a/test/ReaderTaskEither.ts +++ b/test/ReaderTaskEither.ts @@ -827,4 +827,8 @@ describe.concurrent('ReaderTaskEither', () => { it('flatMapIOEither', async () => { U.deepStrictEqual(await _.flatMapIOEither(_.of(1), () => IE.of(2))(undefined)(), E.of(2)) }) + + it('flatMapReaderEither', async () => { + U.deepStrictEqual(await _.flatMapReaderEither(_.of(1), () => RE.of(2))(undefined)(), E.of(2)) + }) }) From 7335eb5072d0e2a8e3f25c8dca2aecbbf8cb8e96 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 19:51:58 +0200 Subject: [PATCH 3/9] feat: flatMapEither --- src/IOOption.ts | 52 +++++++++++++++++++++++++++++------ src/StateReaderTaskEither.ts | 39 ++++++++++++++++++++------ test/IOOption.ts | 23 ++++++++++++++++ test/StateReaderTaskEither.ts | 9 ++++++ 4 files changed, 105 insertions(+), 18 deletions(-) diff --git a/src/IOOption.ts b/src/IOOption.ts index e5ede41be..d8add1fc7 100644 --- a/src/IOOption.ts +++ b/src/IOOption.ts @@ -20,12 +20,7 @@ import { partition as partition_, partitionMap as partitionMap_ } from './Filterable' -import { - chainEitherK as chainEitherK_, - FromEither1, - fromEitherK as fromEitherK_, - tapEither as tapEither_ -} from './FromEither' +import { FromEither1, fromEitherK as fromEitherK_, tapEither as tapEither_ } from './FromEither' import { FromIO1, fromIOK as fromIOK_, tapIO as tapIO_ } from './FromIO' import { dual, flow, identity, LazyArg, pipe, SK } from './function' import { as as as_, asUnit as asUnit_, bindTo as bindTo_, flap as flap_, Functor1, let as let__ } from './Functor' @@ -653,6 +648,11 @@ const _FromIO: _.FromIO = { fromIO: FromIO.fromIO } +/** @internal */ +const _FromEither: _.FromEither = { + fromEither +} + /** * @category sequencing * @since 2.16.0 @@ -662,6 +662,39 @@ export const flatMapIO: { (self: IOOption, f: (a: A) => IO): IOOption } = _.flatMapIO(_FromIO, _FlatMap) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapOption: { + (f: (a: A) => Option): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => Option): IOOption +} = /*#__PURE__*/ dual( + 2, + (self: IOOption, f: (a: A) => Option): IOOption => flatMap(self, fromOptionK(f)) +) + +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapEither: { + (f: (a: A) => Either<_, B>): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => Either<_, B>): IOOption +} = /*#__PURE__*/ _.flatMapEither(_FromEither, _FlatMap) + +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapNullable: { + (f: (a: A) => B | null | undefined): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => B | null | undefined): IOOption +} = /*#__PURE__*/ dual( + 2, + (self: IOOption, f: (a: A) => B | null | undefined): IOOption => flatMap(self, fromNullableK(f)) +) + /** * @category lifting * @since 2.12.0 @@ -694,11 +727,12 @@ export const fromEitherK: , B>( ) => (...a: A) => IOOption = /*#__PURE__*/ fromEitherK_(FromEither) /** - * @category sequencing + * Alias of `flatMapEither`. + * + * @category legacy * @since 2.12.0 */ -export const chainEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption = - /*#__PURE__*/ chainEitherK_(FromEither, Chain) +export const chainEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption = flatMapEither /** * Alias of `tapEither`. diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index 5ccaf4072..babdeb015 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -9,7 +9,6 @@ import * as chainable from './Chain' import * as E from './Either' import { Endomorphism } from './Endomorphism' import { - chainEitherK as chainEitherK_, chainOptionK as chainOptionK_, filterOrElse as filterOrElse_, FromEither4, @@ -419,6 +418,11 @@ const _FromReader: _.FromReader = { fromReader } +/** @internal */ +const _FromEither: _.FromEither = { + fromEither +} + /** * @category sequencing * @since 2.14.0 @@ -516,6 +520,22 @@ export const flatMapIOEither: { ): StateReaderTaskEither => flatMap(self, (a: A) => fromIOEitherK(f)(a)) ) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapEither: { + (f: (a: A) => Either): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => Either): StateReaderTaskEither< + S, + R, + E1 | E2, + B + > +} = /*#__PURE__*/ dual(2, _.flatMapEither(_FromEither, _FlatMap)) + /** * Less strict version of [`flatten`](#flatten). * @@ -1071,29 +1091,30 @@ export const chainOptionKW: ( /*#__PURE__*/ chainOptionK as any /** - * @category sequencing + * Alias of `flatMapEither`. + * + * @category legacy * @since 2.4.0 */ export const chainEitherK: ( f: (a: A) => E.Either -) => (ma: StateReaderTaskEither) => StateReaderTaskEither = /*#__PURE__*/ chainEitherK_( - FromEither, - Chain -) +) => (ma: StateReaderTaskEither) => StateReaderTaskEither = flatMapEither /** + * Alias of `flatMapEither`. + * * Less strict version of [`chainEitherK`](#chaineitherk). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * * The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. * - * @category sequencing + * @category legacy * @since 2.6.1 */ export const chainEitherKW: ( f: (a: A) => Either -) => (ma: StateReaderTaskEither) => StateReaderTaskEither = chainEitherK as any +) => (ma: StateReaderTaskEither) => StateReaderTaskEither = flatMapEither /** * Alias of `tapEither`. @@ -1260,7 +1281,7 @@ export const fromTaskK: , B>( /** * Alias of `flatMapTask`. * - * @category sequencing + * @category legacy * @since 2.10.0 */ export const chainTaskK: ( diff --git a/test/IOOption.ts b/test/IOOption.ts index d2fdf4a68..9cde728e9 100644 --- a/test/IOOption.ts +++ b/test/IOOption.ts @@ -285,4 +285,27 @@ describe.concurrent('IOOption', () => { O.of(2) ) }) + + it('flatMapOption', () => { + const f = _.flatMapOption((n: number) => (n > 0 ? O.some(n) : O.none)) + U.deepStrictEqual(f(_.some(1))(), O.some(1)) + U.deepStrictEqual(f(_.some(-1))(), O.none) + U.deepStrictEqual(f(_.none)(), O.none) + }) + + it('flatMapNullable', () => { + const f = _.chainNullableK((n: number) => (n > 0 ? n : n === 0 ? null : undefined)) + U.deepStrictEqual(f(_.of(1))(), O.some(1)) + U.deepStrictEqual(f(_.of(0))(), O.none) + U.deepStrictEqual(f(_.of(-1))(), O.none) + }) + + it('flatMapEither', () => { + const f = (s: string) => (s.length <= 2 ? E.right(s + '!') : E.left(s.length)) + const g = _.flatMapEither(f) + U.deepStrictEqual(g(_.of(''))(), O.some('!')) + U.deepStrictEqual(g(_.of('a'))(), O.some('a!')) + U.deepStrictEqual(g(_.of('aa'))(), O.some('aa!')) + U.deepStrictEqual(g(_.of('aaa'))(), O.none) + }) }) diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index 7238162ed..59d402290 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -593,4 +593,13 @@ describe.concurrent('StateReaderTaskEither', () => { E.of(2) ) }) + it('flatMapEither', async () => { + U.deepStrictEqual( + await pipe( + _.flatMapEither(_.of(1), () => E.of(2)), + _.evaluate(state) + )(undefined)(), + E.of(2) + ) + }) }) From 705cae87de94849e16682d12b148124cfe35a353 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 20:05:17 +0200 Subject: [PATCH 4/9] feat: flatMapOption --- src/IOOption.ts | 15 ++++++++------- src/StateReaderTaskEither.ts | 23 +++++++++++++++++++++-- test/StateReaderTaskEither.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/IOOption.ts b/src/IOOption.ts index d8add1fc7..951780ebc 100644 --- a/src/IOOption.ts +++ b/src/IOOption.ts @@ -206,13 +206,6 @@ export const chainNullableK: ( export const fromOptionK: , B>(f: (...a: A) => Option) => (...a: A) => IOOption = /*#__PURE__*/ OT.fromOptionK(I.Pointed) -/** - * @category sequencing - * @since 2.12.0 - */ -export const chainOptionK: (f: (a: A) => Option) => (ma: IOOption) => IOOption = - /*#__PURE__*/ OT.chainOptionK(I.Monad) - /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types * use the type constructor `F` to represent some computational context. @@ -742,6 +735,14 @@ export const chainEitherK: (f: (a: A) => Either) => (ma: IOOption */ export const chainFirstEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption = tapEither +/** + * Alias of `flatMapOption`. + * + * @category legacy + * @since 2.12.0 + */ +export const chainOptionK: (f: (a: A) => Option) => (ma: IOOption) => IOOption = flatMapOption + // ------------------------------------------------------------------------------------- // do notation // ------------------------------------------------------------------------------------- diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index babdeb015..80ff4b01e 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -536,6 +536,21 @@ export const flatMapEither: { > } = /*#__PURE__*/ dual(2, _.flatMapEither(_FromEither, _FlatMap)) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapOption: { + (f: (a: A) => Option, onNone: (a: A) => E2): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + ( + self: StateReaderTaskEither, + f: (a: A) => Option, + onNone: (a: A) => E2 + ): StateReaderTaskEither +} = /*#__PURE__*/ _.flatMapOption(_FromEither, _FlatMap) + /** * Less strict version of [`flatten`](#flatten). * @@ -1063,7 +1078,9 @@ export const fromOptionK: ( ) => (...a: A) => StateReaderTaskEither = /*#__PURE__*/ fromOptionK_(FromEither) /** - * @category sequencing + * Use `flatMapOption`. + * + * @category legacy * @since 2.10.0 */ export const chainOptionK: ( @@ -1076,11 +1093,13 @@ export const chainOptionK: ( ) /** + * Use `flatMapOption`. + * * Less strict version of [`chainOptionK`](#chainoptionk). * * The `W` suffix (short for **W**idening) means that the error types will be merged. * - * @category sequencing + * @category legacy * @since 2.13.2 */ export const chainOptionKW: ( diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index 59d402290..c33123058 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -602,4 +602,30 @@ describe.concurrent('StateReaderTaskEither', () => { E.of(2) ) }) + + it('flatMapOption', async () => { + U.deepStrictEqual( + await pipe( + _.flatMapOption( + _.of(1), + () => O.of(2), + () => 'error' + ), + _.evaluate(state) + )(undefined)(), + E.of(2) + ) + + U.deepStrictEqual( + await pipe( + _.flatMapOption( + _.of(1), + () => O.none, + () => 'error' + ), + _.evaluate(state) + )(undefined)(), + E.left('error') + ) + }) }) From b956642b81d77bee104eaf85d817d3e0ddf66136 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 20:09:20 +0200 Subject: [PATCH 5/9] feat: flatMapReaderTaskEither --- src/StateReaderTaskEither.ts | 28 ++++++++++++++++++++++++++-- test/StateReaderTaskEither.ts | 10 ++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index 80ff4b01e..e876bddc8 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -290,9 +290,11 @@ export const fromReaderTaskEitherK = fromReaderTaskEither(f(...a)) /** + * Alias of `flatMapReaderTaskEither`. + * * Less strict version of [`chainReaderTaskEitherK`](#chainreadertaskeitherk). * - * @category sequencing + * @category legacy * @since 2.6.1 */ export const chainReaderTaskEitherKW = @@ -301,7 +303,9 @@ export const chainReaderTaskEitherKW = flatMap(ma, fromReaderTaskEitherK(f)) /** - * @category sequencing + * Alias of `flatMapReaderTaskEither`. + * + * @category legacy * @since 2.4.0 */ export const chainReaderTaskEitherK: ( @@ -551,6 +555,26 @@ export const flatMapOption: { ): StateReaderTaskEither } = /*#__PURE__*/ _.flatMapOption(_FromEither, _FlatMap) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapReaderTaskEither: { + (f: (a: A) => ReaderTaskEither): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + ( + self: StateReaderTaskEither, + f: (a: A) => ReaderTaskEither + ): StateReaderTaskEither +} = /*#__PURE__*/ dual( + 2, + ( + self: StateReaderTaskEither, + f: (a: A) => ReaderTaskEither + ): StateReaderTaskEither => flatMap(self, (a: A) => fromReaderTaskEitherK(f)(a)) +) + /** * Less strict version of [`flatten`](#flatten). * diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index c33123058..b48463241 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -628,4 +628,14 @@ describe.concurrent('StateReaderTaskEither', () => { E.left('error') ) }) + + it('flatMapReaderTaskEither', async () => { + U.deepStrictEqual( + await pipe( + _.flatMapReaderTaskEither(_.of(1), () => RTE.of(2)), + _.evaluate(state) + )(undefined)(), + E.of(2) + ) + }) }) From e67ba03cfb968dd40245e2cd9ac7d6c1d0c1fc3e Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 20:20:59 +0200 Subject: [PATCH 6/9] feat: flatMapState --- src/StateReaderTaskEither.ts | 21 ++++++++++++++++++++- test/StateReaderTaskEither.ts | 12 +++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index e876bddc8..303af902a 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -575,6 +575,23 @@ export const flatMapReaderTaskEither: { ): StateReaderTaskEither => flatMap(self, (a: A) => fromReaderTaskEitherK(f)(a)) ) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapState: { + (f: (a: A) => State): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => State): StateReaderTaskEither +} = /*#__PURE__*/ dual( + 2, + ( + self: StateReaderTaskEither, + f: (a: A) => State + ): StateReaderTaskEither => flatMap(self, fromStateK(f)) +) + /** * Less strict version of [`flatten`](#flatten). * @@ -812,7 +829,9 @@ export const fromStateK: , S, B>( ) => (...a: A) => StateReaderTaskEither = /*#__PURE__*/ fromStateK_(FromState) /** - * @category sequencing + * Alias of `flatMapState`. + * + * @category legacy * @since 2.11.0 */ export const chainStateK: ( diff --git a/test/StateReaderTaskEither.ts b/test/StateReaderTaskEither.ts index b48463241..c82b0ea81 100644 --- a/test/StateReaderTaskEither.ts +++ b/test/StateReaderTaskEither.ts @@ -11,7 +11,7 @@ import * as RE from '../src/ReaderEither' import * as RTE from '../src/ReaderTaskEither' import * as RA from '../src/ReadonlyArray' import { ReadonlyNonEmptyArray } from '../src/ReadonlyNonEmptyArray' -import { State } from '../src/State' +import { of as stateOf, State } from '../src/State' import * as _ from '../src/StateReaderTaskEither' import * as S from '../src/string' import * as T from '../src/Task' @@ -638,4 +638,14 @@ describe.concurrent('StateReaderTaskEither', () => { E.of(2) ) }) + + it('flatMapState', async () => { + U.deepStrictEqual( + await pipe( + _.flatMapState(_.of(1), () => stateOf(2)), + _.evaluate(state) + )(undefined)(), + E.of(2) + ) + }) }) From b811e0f86a19fb4ba067a0311cf9c10025a3eed3 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 20:38:41 +0200 Subject: [PATCH 7/9] feat: flatMapTaskOption --- src/TaskEither.ts | 21 +++++++++++++++++++-- test/TaskEither.ts | 10 ++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/TaskEither.ts b/src/TaskEither.ts index 212365654..e17a1a3d7 100644 --- a/src/TaskEither.ts +++ b/src/TaskEither.ts @@ -398,9 +398,11 @@ export const fromTaskOptionK = ( } /** + * Use `flatMapTaskOption`. + * * The `W` suffix (short for **W**idening) means that the error types will be merged. * - * @category sequencing + * @category legacy * @since 2.12.3 */ export const chainTaskOptionKW = @@ -410,7 +412,9 @@ export const chainTaskOptionKW = flatMap(ma, fromTaskOptionK(onNone)(f)) /** - * @category sequencing + * Use `flatMapTaskOption`. + * + * @category legacy * @since 2.11.0 */ export const chainTaskOptionK: ( @@ -1254,6 +1258,19 @@ export const flatMapIOEither: { flatMap(self, fromIOEitherK(f)) ) +/** + * @category sequencing + * @since 2.16.0 + */ +export const flatMapTaskOption: { + (f: (a: A) => TaskOption, onNone: (a: A) => E2): (self: TaskEither) => TaskEither + (self: TaskEither, f: (a: A) => TaskOption, onNone: (a: A) => E2): TaskEither +} = /*#__PURE__*/ dual( + 3, + (self: TaskEither, f: (a: A) => TaskOption, onNone: (a: A) => E2): TaskEither => + flatMap(self, (a) => fromTaskOption(() => onNone(a))(f(a))) +) + /** * Alias of `flatMapEither`. * diff --git a/test/TaskEither.ts b/test/TaskEither.ts index c9afb8257..6c66b1ad5 100644 --- a/test/TaskEither.ts +++ b/test/TaskEither.ts @@ -854,6 +854,16 @@ describe.concurrent('TaskEither', () => { U.deepStrictEqual(await pipe(_.left('b'), f)(), E.left('b')) }) + it('flatMapTaskOption', async () => { + const f = _.flatMapTaskOption( + (n: number) => (n > 0 ? TO.some(n * 2) : TO.none), + () => 'a' + ) + U.deepStrictEqual(await pipe(_.right(1), f)(), E.right(2)) + U.deepStrictEqual(await pipe(_.right(-1), f)(), E.left('a')) + U.deepStrictEqual(await pipe(_.left('b'), f)(), E.left('b')) + }) + it('tapIO', async () => { const ref: Array = [] const add = (value: number) => () => ref.push(value) From be0057c2e74db5cdbfa74440120782bb80c64b72 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 21:01:52 +0200 Subject: [PATCH 8/9] feat: flatMapNullable --- src/IOOption.ts | 4 +++- test/IOOption.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/IOOption.ts b/src/IOOption.ts index 951780ebc..67a80d288 100644 --- a/src/IOOption.ts +++ b/src/IOOption.ts @@ -188,7 +188,9 @@ export const fromNullableK: , B>( ) => (...a: A) => IOOption> = /*#__PURE__*/ OT.fromNullableK(I.Pointed) /** - * @category sequencing + * Alias of `flatMapNullable`. + * + * @category legacy * @since 2.12.0 */ export const chainNullableK: ( diff --git a/test/IOOption.ts b/test/IOOption.ts index 9cde728e9..5660c20a6 100644 --- a/test/IOOption.ts +++ b/test/IOOption.ts @@ -294,7 +294,7 @@ describe.concurrent('IOOption', () => { }) it('flatMapNullable', () => { - const f = _.chainNullableK((n: number) => (n > 0 ? n : n === 0 ? null : undefined)) + const f = _.flatMapNullable((n: number) => (n > 0 ? n : n === 0 ? null : undefined)) U.deepStrictEqual(f(_.of(1))(), O.some(1)) U.deepStrictEqual(f(_.of(0))(), O.none) U.deepStrictEqual(f(_.of(-1))(), O.none) From bbceba0b1e8dfedc3d99220fa827403e50b56d2d Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 23 May 2023 19:44:22 +0200 Subject: [PATCH 9/9] docs: remaining flatMap functions flatMapReaderIO, flatMapIOEIther, flatMapEither, flatMapOption, flatMapReaderTaskEither, flatMapState --- docs/modules/IOOption.ts.md | 94 ++++-- docs/modules/ReaderTaskEither.ts.md | 162 ++++++---- docs/modules/StateReaderTaskEither.ts.md | 391 +++++++++++++++-------- docs/modules/TaskEither.ts.md | 152 +++++---- 4 files changed, 520 insertions(+), 279 deletions(-) diff --git a/docs/modules/IOOption.ts.md b/docs/modules/IOOption.ts.md index f23002cf4..bbaa40a77 100644 --- a/docs/modules/IOOption.ts.md +++ b/docs/modules/IOOption.ts.md @@ -69,10 +69,13 @@ Added in v2.12.0 - [Zero](#zero) - [legacy](#legacy) - [chain](#chain) + - [chainEitherK](#chaineitherk) - [chainFirst](#chainfirst) - [chainFirstEitherK](#chainfirsteitherk) - [chainFirstIOK](#chainfirstiok) - [chainIOK](#chainiok) + - [chainNullableK](#chainnullablek) + - [chainOptionK](#chainoptionk) - [lifting](#lifting) - [fromEitherK](#fromeitherk) - [fromIOK](#fromiok) @@ -93,11 +96,11 @@ Added in v2.12.0 - [matchEW](#matchew) - [matchW](#matchw) - [sequencing](#sequencing) - - [chainEitherK](#chaineitherk) - - [chainNullableK](#chainnullablek) - - [chainOptionK](#chainoptionk) - [flatMap](#flatmap) + - [flatMapEither](#flatmapeither) - [flatMapIO](#flatmapio) + - [flatMapNullable](#flatmapnullable) + - [flatMapOption](#flatmapoption) - [flatten](#flatten) - [traversing](#traversing) - [traverseReadonlyArrayWithIndex](#traversereadonlyarraywithindex) @@ -663,6 +666,18 @@ export declare const chain: (f: (a: A) => IOOption) => (ma: IOOption Added in v2.12.0 +## chainEitherK + +Alias of `flatMapEither`. + +**Signature** + +```ts +export declare const chainEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption +``` + +Added in v2.12.0 + ## chainFirst Alias of `tap`. @@ -711,6 +726,32 @@ export declare const chainIOK: (f: (a: A) => I.IO) => (first: IOOption< Added in v2.12.0 +## chainNullableK + +Alias of `flatMapNullable`. + +**Signature** + +```ts +export declare const chainNullableK: ( + f: (a: A) => B | null | undefined +) => (ma: IOOption) => IOOption> +``` + +Added in v2.12.0 + +## chainOptionK + +Alias of `flatMapOption`. + +**Signature** + +```ts +export declare const chainOptionK: (f: (a: A) => O.Option) => (ma: IOOption) => IOOption +``` + +Added in v2.12.0 + # lifting ## fromEitherK @@ -906,59 +947,66 @@ Added in v2.12.0 # sequencing -## chainEitherK +## flatMap **Signature** ```ts -export declare const chainEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption +export declare const flatMap: { + (f: (a: A) => IOOption): (ma: IOOption) => IOOption + (ma: IOOption, f: (a: A) => IOOption): IOOption +} ``` -Added in v2.12.0 +Added in v2.14.0 -## chainNullableK +## flatMapEither **Signature** ```ts -export declare const chainNullableK: ( - f: (a: A) => B | null | undefined -) => (ma: IOOption) => IOOption> +export declare const flatMapEither: { + (f: (a: A) => Either<_, B>): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => Either<_, B>): IOOption +} ``` -Added in v2.12.0 +Added in v2.16.0 -## chainOptionK +## flatMapIO **Signature** ```ts -export declare const chainOptionK: (f: (a: A) => O.Option) => (ma: IOOption) => IOOption +export declare const flatMapIO: { + (f: (a: A) => I.IO): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => I.IO): IOOption +} ``` -Added in v2.12.0 +Added in v2.16.0 -## flatMap +## flatMapNullable **Signature** ```ts -export declare const flatMap: { - (f: (a: A) => IOOption): (ma: IOOption) => IOOption - (ma: IOOption, f: (a: A) => IOOption): IOOption +export declare const flatMapNullable: { + (f: (a: A) => B | null | undefined): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => B | null | undefined): IOOption } ``` -Added in v2.14.0 +Added in v2.16.0 -## flatMapIO +## flatMapOption **Signature** ```ts -export declare const flatMapIO: { - (f: (a: A) => I.IO): (self: IOOption) => IOOption - (self: IOOption, f: (a: A) => I.IO): IOOption +export declare const flatMapOption: { + (f: (a: A) => O.Option): (self: IOOption) => IOOption + (self: IOOption, f: (a: A) => O.Option): IOOption } ``` diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index 6a448f2a6..7b30da0e9 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -117,10 +117,14 @@ Added in v2.0.0 - [chainFirstTaskEitherKW](#chainfirsttaskeitherkw) - [chainFirstTaskK](#chainfirsttaskk) - [chainFirstW](#chainfirstw) + - [chainIOEitherK](#chainioeitherk) + - [chainIOEitherKW](#chainioeitherkw) - [chainIOK](#chainiok) - [chainNullableK](#chainnullablek) - [chainOptionK](#chainoptionk) - [chainOptionKW](#chainoptionkw) + - [chainReaderEitherK](#chainreadereitherk) + - [chainReaderEitherKW](#chainreadereitherkw) - [chainReaderIOK](#chainreaderiok) - [chainReaderIOKW](#chainreaderiokw) - [chainReaderK](#chainreaderk) @@ -164,16 +168,14 @@ Added in v2.0.0 - [matchEW](#matchew) - [matchW](#matchw) - [sequencing](#sequencing) - - [chainIOEitherK](#chainioeitherk) - - [chainIOEitherKW](#chainioeitherkw) - - [chainReaderEitherK](#chainreadereitherk) - - [chainReaderEitherKW](#chainreadereitherkw) - [flatMap](#flatmap) - [flatMapEither](#flatmapeither) - [flatMapIO](#flatmapio) + - [flatMapIOEither](#flatmapioeither) - [flatMapNullable](#flatmapnullable) - [flatMapOption](#flatmapoption) - [flatMapReader](#flatmapreader) + - [flatMapReaderEither](#flatmapreadereither) - [flatMapReaderIO](#flatmapreaderio) - [flatMapReaderTask](#flatmapreadertask) - [flatMapTask](#flatmaptask) @@ -1619,6 +1621,38 @@ export declare const chainFirstW: ( Added in v2.8.0 +## chainIOEitherK + +Alias of `flatMapIOEither`. + +**Signature** + +```ts +export declare const chainIOEitherK: ( + f: (a: A) => IOEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.4.0 + +## chainIOEitherKW + +Alias of `flatMapIOEither`. + +Less strict version of [`chainIOEitherK`](#chainioeitherk). + +The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. + +**Signature** + +```ts +export declare const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.6.1 + ## chainIOK Alias of `flatMapIO`. @@ -1677,6 +1711,38 @@ export declare const chainOptionKW: ( Added in v2.13.2 +## chainReaderEitherK + +Alias of `flatMapReaderEither`. + +**Signature** + +```ts +export declare const chainReaderEitherK: ( + f: (a: A) => ReaderEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.11.0 + +## chainReaderEitherKW + +Alias of `flatMapReaderEither`. + +Less strict version of [`chainReaderEitherK`](#chainreadereitherk). + +The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. + +**Signature** + +```ts +export declare const chainReaderEitherKW: ( + f: (a: A) => ReaderEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.11.0 + ## chainReaderIOK Alias of `flatMapReaderIO`. @@ -2219,62 +2285,6 @@ Added in v2.10.0 # sequencing -## chainIOEitherK - -**Signature** - -```ts -export declare const chainIOEitherK: ( - f: (a: A) => IOEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.4.0 - -## chainIOEitherKW - -Less strict version of [`chainIOEitherK`](#chainioeitherk). - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. - -**Signature** - -```ts -export declare const chainIOEitherKW: ( - f: (a: A) => IOEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.6.1 - -## chainReaderEitherK - -**Signature** - -```ts -export declare const chainReaderEitherK: ( - f: (a: A) => ReaderEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.11.0 - -## chainReaderEitherKW - -Less strict version of [`chainReaderEitherK`](#chainreadereitherk). - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. - -**Signature** - -```ts -export declare const chainReaderEitherKW: ( - f: (a: A) => ReaderEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.11.0 - ## flatMap **Signature** @@ -2320,6 +2330,19 @@ export declare const flatMapIO: { Added in v2.16.0 +## flatMapIOEither + +**Signature** + +```ts +export declare const flatMapIOEither: { + (f: (a: A) => IOEither): (self: ReaderTaskEither) => ReaderTaskEither + (self: ReaderTaskEither, f: (a: A) => IOEither): ReaderTaskEither +} +``` + +Added in v2.16.0 + ## flatMapNullable **Signature** @@ -2371,6 +2394,25 @@ export declare const flatMapReader: { Added in v2.16.0 +## flatMapReaderEither + +**Signature** + +```ts +export declare const flatMapReaderEither: { + (f: (a: A) => ReaderEither): ( + self: ReaderTaskEither + ) => ReaderTaskEither + (self: ReaderTaskEither, f: (a: A) => ReaderEither): ReaderTaskEither< + R1 & R2, + E1 | E2, + B + > +} +``` + +Added in v2.16.0 + ## flatMapReaderIO **Signature** diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index cd4995e7a..8f558905b 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -77,6 +77,8 @@ Added in v2.0.0 - [Pointed](#pointed) - [legacy](#legacy) - [chain](#chain) + - [chainEitherK](#chaineitherk) + - [chainEitherKW](#chaineitherkw) - [chainFirst](#chainfirst) - [chainFirstEitherK](#chainfirsteitherk) - [chainFirstEitherKW](#chainfirsteitherkw) @@ -85,11 +87,19 @@ Added in v2.0.0 - [chainFirstReaderKW](#chainfirstreaderkw) - [chainFirstTaskK](#chainfirsttaskk) - [chainFirstW](#chainfirstw) + - [chainIOEitherK](#chainioeitherk) + - [chainIOEitherKW](#chainioeitherkw) - [chainIOK](#chainiok) + - [chainOptionK](#chainoptionk) + - [chainOptionKW](#chainoptionkw) - [chainReaderK](#chainreaderk) - [chainReaderKW](#chainreaderkw) + - [chainReaderTaskEitherK](#chainreadertaskeitherk) + - [chainReaderTaskEitherKW](#chainreadertaskeitherkw) + - [chainStateK](#chainstatek) - [chainTaskEitherK](#chaintaskeitherk) - [chainTaskEitherKW](#chaintaskeitherkw) + - [chainTaskK](#chaintaskk) - [chainW](#chainw) - [lifting](#lifting) - [fromEitherK](#fromeitherk) @@ -111,19 +121,14 @@ Added in v2.0.0 - [model](#model) - [StateReaderTaskEither (interface)](#statereadertaskeither-interface) - [sequencing](#sequencing) - - [chainEitherK](#chaineitherk) - - [chainEitherKW](#chaineitherkw) - - [chainIOEitherK](#chainioeitherk) - - [chainIOEitherKW](#chainioeitherkw) - - [chainOptionK](#chainoptionk) - - [chainOptionKW](#chainoptionkw) - - [chainReaderTaskEitherK](#chainreadertaskeitherk) - - [chainReaderTaskEitherKW](#chainreadertaskeitherkw) - - [chainStateK](#chainstatek) - - [chainTaskK](#chaintaskk) - [flatMap](#flatmap) + - [flatMapEither](#flatmapeither) - [flatMapIO](#flatmapio) + - [flatMapIOEither](#flatmapioeither) + - [flatMapOption](#flatmapoption) - [flatMapReader](#flatmapreader) + - [flatMapReaderTaskEither](#flatmapreadertaskeither) + - [flatMapState](#flatmapstate) - [flatMapTask](#flatmaptask) - [flatMapTaskEither](#flatmaptaskeither) - [flatten](#flatten) @@ -873,6 +878,40 @@ export declare const chain: ( Added in v2.0.0 +## chainEitherK + +Alias of `flatMapEither`. + +**Signature** + +```ts +export declare const chainEitherK: ( + f: (a: A) => E.Either +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.4.0 + +## chainEitherKW + +Alias of `flatMapEither`. + +Less strict version of [`chainEitherK`](#chaineitherk). + +The `W` suffix (short for **W**idening) means that the error types will be merged. + +The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. + +**Signature** + +```ts +export declare const chainEitherKW: ( + f: (a: A) => E.Either +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.6.1 + ## chainFirst Alias of `tap`. @@ -993,6 +1032,36 @@ export declare const chainFirstW: ( Added in v2.8.0 +## chainIOEitherK + +Alias of `flatMapIOEither`. + +**Signature** + +```ts +export declare const chainIOEitherK: ( + f: (a: A) => IOEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.4.0 + +## chainIOEitherKW + +Alias of `flatMapIOEither`. + +Less strict version of [`chainIOEitherK`](#chainioeitherk). + +**Signature** + +```ts +export declare const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.6.1 + ## chainIOK Alias of `flatMapIO`. @@ -1007,6 +1076,42 @@ export declare const chainIOK: ( Added in v2.10.0 +## chainOptionK + +Use `flatMapOption`. + +**Signature** + +```ts +export declare const chainOptionK: ( + onNone: LazyArg +) => ( + f: (a: A) => Option +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.10.0 + +## chainOptionKW + +Use `flatMapOption`. + +Less strict version of [`chainOptionK`](#chainoptionk). + +The `W` suffix (short for **W**idening) means that the error types will be merged. + +**Signature** + +```ts +export declare const chainOptionKW: ( + onNone: LazyArg +) => ( + f: (a: A) => Option +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.13.2 + ## chainReaderK Alias of `flatMapReader`. @@ -1039,6 +1144,50 @@ export declare const chainReaderKW: ( Added in v2.11.0 +## chainReaderTaskEitherK + +Alias of `flatMapReaderTaskEither`. + +**Signature** + +```ts +export declare const chainReaderTaskEitherK: ( + f: (a: A) => RTE.ReaderTaskEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.4.0 + +## chainReaderTaskEitherKW + +Alias of `flatMapReaderTaskEither`. + +Less strict version of [`chainReaderTaskEitherK`](#chainreadertaskeitherk). + +**Signature** + +```ts +export declare const chainReaderTaskEitherKW: ( + f: (a: A) => RTE.ReaderTaskEither +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.6.1 + +## chainStateK + +Alias of `flatMapState`. + +**Signature** + +```ts +export declare const chainStateK: ( + f: (a: A) => State +) => (ma: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.11.0 + ## chainTaskEitherK Alias of `flatMapTaskEither`. @@ -1069,6 +1218,20 @@ export declare const chainTaskEitherKW: ( Added in v2.6.1 +## chainTaskK + +Alias of `flatMapTask`. + +**Signature** + +```ts +export declare const chainTaskK: ( + f: (a: A) => Task +) => (first: StateReaderTaskEither) => StateReaderTaskEither +``` + +Added in v2.10.0 + ## chainW Alias of `flatMap`. @@ -1302,192 +1465,144 @@ Added in v2.0.0 # sequencing -## chainEitherK - -**Signature** - -```ts -export declare const chainEitherK: ( - f: (a: A) => E.Either -) => (ma: StateReaderTaskEither) => StateReaderTaskEither -``` - -Added in v2.4.0 - -## chainEitherKW - -Less strict version of [`chainEitherK`](#chaineitherk). - -The `W` suffix (short for **W**idening) means that the error types will be merged. - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. - -**Signature** - -```ts -export declare const chainEitherKW: ( - f: (a: A) => E.Either -) => (ma: StateReaderTaskEither) => StateReaderTaskEither -``` - -Added in v2.6.1 - -## chainIOEitherK - -**Signature** - -```ts -export declare const chainIOEitherK: ( - f: (a: A) => IOEither -) => (ma: StateReaderTaskEither) => StateReaderTaskEither -``` - -Added in v2.4.0 - -## chainIOEitherKW - -Less strict version of [`chainIOEitherK`](#chainioeitherk). - -**Signature** - -```ts -export declare const chainIOEitherKW: ( - f: (a: A) => IOEither -) => (ma: StateReaderTaskEither) => StateReaderTaskEither -``` - -Added in v2.6.1 - -## chainOptionK +## flatMap **Signature** ```ts -export declare const chainOptionK: ( - onNone: LazyArg -) => ( - f: (a: A) => Option -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMap: { + (f: (a: A) => StateReaderTaskEither): ( + ma: StateReaderTaskEither + ) => StateReaderTaskEither + ( + ma: StateReaderTaskEither, + f: (a: A) => StateReaderTaskEither + ): StateReaderTaskEither +} ``` -Added in v2.10.0 - -## chainOptionKW - -Less strict version of [`chainOptionK`](#chainoptionk). +Added in v2.14.0 -The `W` suffix (short for **W**idening) means that the error types will be merged. +## flatMapEither **Signature** ```ts -export declare const chainOptionKW: ( - onNone: LazyArg -) => ( - f: (a: A) => Option -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMapEither: { + (f: (a: A) => E.Either): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => E.Either): StateReaderTaskEither< + S, + R, + E1 | E2, + B + > +} ``` -Added in v2.13.2 +Added in v2.16.0 -## chainReaderTaskEitherK +## flatMapIO **Signature** ```ts -export declare const chainReaderTaskEitherK: ( - f: (a: A) => RTE.ReaderTaskEither -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMapIO: { + (f: (a: A) => IO): (self: StateReaderTaskEither) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => IO): StateReaderTaskEither +} ``` -Added in v2.4.0 - -## chainReaderTaskEitherKW +Added in v2.16.0 -Less strict version of [`chainReaderTaskEitherK`](#chainreadertaskeitherk). +## flatMapIOEither **Signature** ```ts -export declare const chainReaderTaskEitherKW: ( - f: (a: A) => RTE.ReaderTaskEither -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMapIOEither: { + (f: (a: A) => IOEither): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => IOEither): StateReaderTaskEither< + S, + R, + E1 | E2, + B + > +} ``` -Added in v2.6.1 +Added in v2.16.0 -## chainStateK +## flatMapOption **Signature** ```ts -export declare const chainStateK: ( - f: (a: A) => State -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMapOption: { + (f: (a: A) => Option, onNone: (a: A) => E2): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + ( + self: StateReaderTaskEither, + f: (a: A) => Option, + onNone: (a: A) => E2 + ): StateReaderTaskEither +} ``` -Added in v2.11.0 - -## chainTaskK +Added in v2.16.0 -Alias of `flatMapTask`. +## flatMapReader **Signature** ```ts -export declare const chainTaskK: ( - f: (a: A) => Task -) => (first: StateReaderTaskEither) => StateReaderTaskEither +export declare const flatMapReader: { + (f: (a: A) => R.Reader): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => R.Reader): StateReaderTaskEither< + S, + R1 & R2, + E, + B + > +} ``` -Added in v2.10.0 +Added in v2.16.0 -## flatMap +## flatMapReaderTaskEither **Signature** ```ts -export declare const flatMap: { - (f: (a: A) => StateReaderTaskEither): ( - ma: StateReaderTaskEither +export declare const flatMapReaderTaskEither: { + (f: (a: A) => RTE.ReaderTaskEither): ( + self: StateReaderTaskEither ) => StateReaderTaskEither ( - ma: StateReaderTaskEither, - f: (a: A) => StateReaderTaskEither + self: StateReaderTaskEither, + f: (a: A) => RTE.ReaderTaskEither ): StateReaderTaskEither } ``` -Added in v2.14.0 - -## flatMapIO - -**Signature** - -```ts -export declare const flatMapIO: { - (f: (a: A) => IO): (self: StateReaderTaskEither) => StateReaderTaskEither - (self: StateReaderTaskEither, f: (a: A) => IO): StateReaderTaskEither -} -``` - Added in v2.16.0 -## flatMapReader +## flatMapState **Signature** ```ts -export declare const flatMapReader: { - (f: (a: A) => R.Reader): ( - self: StateReaderTaskEither - ) => StateReaderTaskEither - (self: StateReaderTaskEither, f: (a: A) => R.Reader): StateReaderTaskEither< - S, - R1 & R2, - E, - B - > +export declare const flatMapState: { + (f: (a: A) => State): ( + self: StateReaderTaskEither + ) => StateReaderTaskEither + (self: StateReaderTaskEither, f: (a: A) => State): StateReaderTaskEither } ``` diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md index 519560854..c26e0f16a 100644 --- a/docs/modules/TaskEither.ts.md +++ b/docs/modules/TaskEither.ts.md @@ -101,11 +101,15 @@ Added in v2.0.0 - [chainFirstIOK](#chainfirstiok) - [chainFirstTaskK](#chainfirsttaskk) - [chainFirstW](#chainfirstw) + - [chainIOEitherK](#chainioeitherk) + - [chainIOEitherKW](#chainioeitherkw) - [chainIOK](#chainiok) - [chainNullableK](#chainnullablek) - [chainOptionK](#chainoptionk) - [chainOptionKW](#chainoptionkw) - [chainTaskK](#chaintaskk) + - [chainTaskOptionK](#chaintaskoptionk) + - [chainTaskOptionKW](#chaintaskoptionkw) - [chainW](#chainw) - [fromNullableK](#fromnullablek) - [fromOptionK](#fromoptionk) @@ -136,16 +140,14 @@ Added in v2.0.0 - [matchEW](#matchew) - [matchW](#matchw) - [sequencing](#sequencing) - - [chainIOEitherK](#chainioeitherk) - - [chainIOEitherKW](#chainioeitherkw) - - [chainTaskOptionK](#chaintaskoptionk) - - [chainTaskOptionKW](#chaintaskoptionkw) - [flatMap](#flatmap) - [flatMapEither](#flatmapeither) - [flatMapIO](#flatmapio) + - [flatMapIOEither](#flatmapioeither) - [flatMapNullable](#flatmapnullable) - [flatMapOption](#flatmapoption) - [flatMapTask](#flatmaptask) + - [flatMapTaskOption](#flatmaptaskoption) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -1343,6 +1345,38 @@ export declare const chainFirstW: ( Added in v2.8.0 +## chainIOEitherK + +Alias of `flatMapIOEither`. + +**Signature** + +```ts +export declare const chainIOEitherK: ( + f: (a: A) => IOEither +) => (ma: TaskEither) => TaskEither +``` + +Added in v2.4.0 + +## chainIOEitherKW + +Alias of `flatMapIOEither`. + +Less strict version of [`chainIOEitherK`](#chainioeitherk). + +The `W` suffix (short for **W**idening) means that the error types will be merged. + +**Signature** + +```ts +export declare const chainIOEitherKW: ( + f: (a: A) => IOEither +) => (ma: TaskEither) => TaskEither +``` + +Added in v2.6.1 + ## chainIOK Alias of `flatMapIO`. @@ -1409,6 +1443,36 @@ export declare const chainTaskK: (f: (a: A) => T.Task) => (first: Ta Added in v2.10.0 +## chainTaskOptionK + +Use `flatMapTaskOption`. + +**Signature** + +```ts +export declare const chainTaskOptionK: ( + onNone: LazyArg +) => (f: (a: A) => TaskOption) => (ma: TaskEither) => TaskEither +``` + +Added in v2.11.0 + +## chainTaskOptionKW + +Use `flatMapTaskOption`. + +The `W` suffix (short for **W**idening) means that the error types will be merged. + +**Signature** + +```ts +export declare const chainTaskOptionKW: ( + onNone: LazyArg +) => (f: (a: A) => TaskOption) => (ma: TaskEither) => TaskEither +``` + +Added in v2.12.3 + ## chainW Alias of `flatMap`. @@ -1752,60 +1816,6 @@ Added in v2.10.0 # sequencing -## chainIOEitherK - -**Signature** - -```ts -export declare const chainIOEitherK: ( - f: (a: A) => IOEither -) => (ma: TaskEither) => TaskEither -``` - -Added in v2.4.0 - -## chainIOEitherKW - -Less strict version of [`chainIOEitherK`](#chainioeitherk). - -The `W` suffix (short for **W**idening) means that the error types will be merged. - -**Signature** - -```ts -export declare const chainIOEitherKW: ( - f: (a: A) => IOEither -) => (ma: TaskEither) => TaskEither -``` - -Added in v2.6.1 - -## chainTaskOptionK - -**Signature** - -```ts -export declare const chainTaskOptionK: ( - onNone: LazyArg -) => (f: (a: A) => TaskOption) => (ma: TaskEither) => TaskEither -``` - -Added in v2.11.0 - -## chainTaskOptionKW - -The `W` suffix (short for **W**idening) means that the error types will be merged. - -**Signature** - -```ts -export declare const chainTaskOptionKW: ( - onNone: LazyArg -) => (f: (a: A) => TaskOption) => (ma: TaskEither) => TaskEither -``` - -Added in v2.12.3 - ## flatMap **Signature** @@ -1845,6 +1855,19 @@ export declare const flatMapIO: { Added in v2.15.0 +## flatMapIOEither + +**Signature** + +```ts +export declare const flatMapIOEither: { + (f: (a: A) => IOEither): (self: TaskEither) => TaskEither + (self: TaskEither, f: (a: A) => IOEither): TaskEither +} +``` + +Added in v2.16.0 + ## flatMapNullable **Signature** @@ -1889,6 +1912,19 @@ export declare const flatMapTask: { Added in v2.16.0 +## flatMapTaskOption + +**Signature** + +```ts +export declare const flatMapTaskOption: { + (f: (a: A) => TaskOption, onNone: (a: A) => E2): (self: TaskEither) => TaskEither + (self: TaskEither, f: (a: A) => TaskOption, onNone: (a: A) => E2): TaskEither +} +``` + +Added in v2.16.0 + ## flatten **Signature**