diff --git a/docs/modules/Array.ts.md b/docs/modules/Array.ts.md index 035a25075..e96f5452a 100644 --- a/docs/modules/Array.ts.md +++ b/docs/modules/Array.ts.md @@ -112,6 +112,7 @@ Added in v2.0.0 - [chainRecBreadthFirst](#chainrecbreadthfirst) - [chainRecDepthFirst](#chainrecdepthfirst) - [chainWithIndex](#chainwithindex) + - [flatMap](#flatmap) - [flatten](#flatten) - [traverseWithIndex](#traversewithindex) - [traversing](#traversing) @@ -1701,15 +1702,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to -determine the next computation. - -In other words it takes a function `f` that produces an array from a single element of -the base type `A` and returns a new function which applies `f` to each element of the -input array (like [`map`](#map)) and, instead of returning an array of arrays, concatenates the -results into a single array (like [`flatten`](#flatten)). - -This is the `chain` component of the array `Monad`. +Alias of `flatMap`. **Signature** @@ -1717,17 +1710,6 @@ This is the `chain` component of the array `Monad`. export declare const chain: (f: (a: A) => B[]) => (ma: A[]) => B[] ``` -**Example** - -```ts -import { chain, map, replicate } from 'fp-ts/Array' -import { pipe } from 'fp-ts/function' - -const f = (n: number) => replicate(n, `${n}`) -assert.deepStrictEqual(pipe([1, 2, 3], map(f)), [['1'], ['2', '2'], ['3', '3', '3']]) -assert.deepStrictEqual(pipe([1, 2, 3], chain(f)), ['1', '2', '2', '3', '3', '3']) -``` - Added in v2.0.0 ## chainFirst @@ -1807,6 +1789,35 @@ assert.deepStrictEqual(pipe(['a', 'b', 'c'], chainWithIndex(f)), ['a0', 'a0', 'b Added in v2.7.0 +## flatMap + +Composes computations in sequence, using the return value of one computation to +determine the next computation. + +In other words it takes a function `f` that produces an array from a single element of +the base type `A` and returns a new function which applies `f` to each element of the +input array (like [`map`](#map)) and, instead of returning an array of arrays, concatenates the +results into a single array (like [`flatten`](#flatten)). + +**Signature** + +```ts +export declare const flatMap: { (f: (a: A) => B[]): (ma: A[]) => B[]; (ma: A[], f: (a: A) => B[]): B[] } +``` + +**Example** + +```ts +import { flatMap, map, replicate } from 'fp-ts/Array' +import { pipe } from 'fp-ts/function' + +const f = (n: number) => replicate(n, `${n}`) +assert.deepStrictEqual(pipe([1, 2, 3], map(f)), [['1'], ['2', '2'], ['3', '3', '3']]) +assert.deepStrictEqual(pipe([1, 2, 3], flatMap(f)), ['1', '2', '2', '3', '3', '3']) +``` + +Added in v2.14.0 + ## flatten Takes an array of arrays of `A` and flattens them into an array of `A` diff --git a/docs/modules/Either.ts.md b/docs/modules/Either.ts.md index 1e39965aa..28faebae4 100644 --- a/docs/modules/Either.ts.md +++ b/docs/modules/Either.ts.md @@ -158,6 +158,7 @@ Added in v2.0.0 - [chainOptionK](#chainoptionk) - [chainOptionKW](#chainoptionkw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -1327,7 +1328,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1408,9 +1409,7 @@ Added in v2.13.2 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1418,30 +1417,20 @@ The `W` suffix (short for **W**idening) means that the error types will be merge export declare const chainW: (f: (a: A) => Either) => (ma: Either) => Either ``` -**Example** - -```ts -import * as E from 'fp-ts/Either' -import { pipe } from 'fp-ts/function' +Added in v2.6.0 -const e1: E.Either = E.right(1) -const e2: E.Either = E.right(2) +## flatMap -export const result1 = pipe( - // @ts-expect-error - e1, - E.chain(() => e2) -) +**Signature** -// merged error types -----v-------------v -// const result2: E.Either -export const result2 = pipe( - e1, // no error - E.chainW(() => e2) -) +```ts +export declare const flatMap: { + (f: (a: A) => Either): (ma: Either) => Either + (ma: Either, f: (a: A) => Either): Either +} ``` -Added in v2.6.0 +Added in v2.14.0 ## flatten diff --git a/docs/modules/IO.ts.md b/docs/modules/IO.ts.md index 0c3be2fd4..818e93e81 100644 --- a/docs/modules/IO.ts.md +++ b/docs/modules/IO.ts.md @@ -50,6 +50,7 @@ Added in v2.0.0 - [sequencing](#sequencing) - [chain](#chain) - [chainFirst](#chainfirst) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequenceArray](#sequencearray) @@ -281,7 +282,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -304,6 +305,19 @@ export declare const chainFirst: (f: (a: A) => IO) => (first: IO) => Added in v2.0.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => IO): (ma: IO) => IO + (ma: IO, f: (a: A) => IO): IO +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/IOEither.ts.md b/docs/modules/IOEither.ts.md index 63df300d1..7dd6ff5ac 100644 --- a/docs/modules/IOEither.ts.md +++ b/docs/modules/IOEither.ts.md @@ -104,6 +104,7 @@ Added in v2.0.0 - [chainOptionK](#chainoptionk) - [chainOptionKW](#chainoptionkw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -917,7 +918,7 @@ Added in v2.10.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1056,9 +1057,7 @@ Added in v2.13.2 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1070,6 +1069,19 @@ export declare const chainW: ( Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => IOEither): (ma: IOEither) => IOEither + (ma: IOEither, f: (a: A) => IOEither): IOEither +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/IOOption.ts.md b/docs/modules/IOOption.ts.md index 715e2dd5b..9f6919a4f 100644 --- a/docs/modules/IOOption.ts.md +++ b/docs/modules/IOOption.ts.md @@ -89,6 +89,7 @@ Added in v2.12.0 - [chainIOK](#chainiok) - [chainNullableK](#chainnullablek) - [chainOptionK](#chainoptionk) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [traverseReadonlyArrayWithIndex](#traversereadonlyarraywithindex) @@ -714,6 +715,8 @@ Added in v2.12.0 ## chain +Alias of `flatMap`. + **Signature** ```ts @@ -797,6 +800,19 @@ export declare const chainOptionK: (f: (a: A) => O.Option) => (ma: IOOp Added in v2.12.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => IOOption): (ma: IOOption) => IOOption + (ma: IOOption, f: (a: A) => IOOption): IOOption +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/Identity.ts.md b/docs/modules/Identity.ts.md index 39ad19813..145fc4b5a 100644 --- a/docs/modules/Identity.ts.md +++ b/docs/modules/Identity.ts.md @@ -51,6 +51,7 @@ Added in v2.0.0 - [sequencing](#sequencing) - [chain](#chain) - [chainFirst](#chainfirst) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequence](#sequence) @@ -388,7 +389,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -411,6 +412,16 @@ export declare const chainFirst: (f: (a: A) => B) => (first: A) => A Added in v2.0.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { (f: (a: A) => B): (ma: A) => B; (ma: A, f: (a: A) => B): B } +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/NonEmptyArray.ts.md b/docs/modules/NonEmptyArray.ts.md index b29b90334..5e26d31af 100644 --- a/docs/modules/NonEmptyArray.ts.md +++ b/docs/modules/NonEmptyArray.ts.md @@ -77,6 +77,7 @@ Added in v2.0.0 - [chain](#chain) - [chainFirst](#chainfirst) - [chainWithIndex](#chainwithindex) + - [flatMap](#flatmap) - [flatten](#flatten) - [traverseWithIndex](#traversewithindex) - [traversing](#traversing) @@ -686,7 +687,7 @@ Added in v2.11.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -694,21 +695,6 @@ Composes computations in sequence, using the return value of one computation to export declare const chain: (f: (a: A) => NonEmptyArray) => (ma: NonEmptyArray) => NonEmptyArray ``` -**Example** - -```ts -import * as NEA from 'fp-ts/NonEmptyArray' -import { pipe } from 'fp-ts/function' - -assert.deepStrictEqual( - pipe( - [1, 2, 3], - NEA.chain((n) => [`a${n}`, `b${n}`]) - ), - ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] -) -``` - Added in v2.0.0 ## chainFirst @@ -736,6 +722,34 @@ export declare const chainWithIndex: ( Added in v2.10.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => NonEmptyArray): (ma: NonEmptyArray) => NonEmptyArray + (ma: NonEmptyArray, f: (a: A) => NonEmptyArray): NonEmptyArray +} +``` + +**Example** + +```ts +import * as NEA from 'fp-ts/NonEmptyArray' +import { pipe } from 'fp-ts/function' + +assert.deepStrictEqual( + pipe( + [1, 2, 3], + NEA.flatMap((n) => [`a${n}`, `b${n}`]) + ), + ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] +) +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/Option.ts.md b/docs/modules/Option.ts.md index 0d3a7dd7c..51e21758d 100644 --- a/docs/modules/Option.ts.md +++ b/docs/modules/Option.ts.md @@ -157,6 +157,7 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstEitherK](#chainfirsteitherk) - [chainNullableK](#chainnullablek) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequence](#sequence) @@ -1244,7 +1245,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1342,6 +1343,19 @@ assert.deepStrictEqual( Added in v2.9.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => Option): (ma: Option) => Option + (ma: Option, f: (a: A) => Option): Option +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/Reader.ts.md b/docs/modules/Reader.ts.md index c1ce7ffa7..ad9ba365b 100644 --- a/docs/modules/Reader.ts.md +++ b/docs/modules/Reader.ts.md @@ -90,6 +90,7 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstW](#chainfirstw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -433,7 +434,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -474,9 +475,7 @@ Added in v2.11.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types will be merged. +Alias of `flatMap`. **Signature** @@ -486,6 +485,19 @@ export declare const chainW: (f: (a: A) => Reader) => (ma: Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => Reader): (ma: Reader) => Reader + (ma: Reader, f: (a: A) => Reader): Reader +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index 883340d63..06d71761d 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -98,6 +98,7 @@ Added in v2.0.0 - [chainReaderK](#chainreaderk) - [chainReaderKW](#chainreaderkw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -923,7 +924,7 @@ Added in v2.10.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1108,9 +1109,7 @@ Added in v2.11.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1122,6 +1121,25 @@ export declare const chainW: ( Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => ReaderEither): ( + ma: ReaderEither + ) => ReaderEither + (ma: ReaderEither, f: (a: A) => ReaderEither): ReaderEither< + R1 & R2, + E1 | E2, + B + > +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReaderIO.ts.md b/docs/modules/ReaderIO.ts.md index c346a78e0..a950bb079 100644 --- a/docs/modules/ReaderIO.ts.md +++ b/docs/modules/ReaderIO.ts.md @@ -57,6 +57,7 @@ Added in v2.13.0 - [chainReaderK](#chainreaderk) - [chainReaderKW](#chainreaderkw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -403,7 +404,7 @@ Added in v2.13.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -516,9 +517,7 @@ Added in v2.13.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types will be merged. +Alias of `flatMap`. **Signature** @@ -530,6 +529,19 @@ export declare const chainW: ( Added in v2.13.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => ReaderIO): (ma: ReaderIO) => ReaderIO + (ma: ReaderIO, f: (a: A) => ReaderIO): ReaderIO +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReaderTask.ts.md b/docs/modules/ReaderTask.ts.md index 48c0eccfe..8aae0c254 100644 --- a/docs/modules/ReaderTask.ts.md +++ b/docs/modules/ReaderTask.ts.md @@ -72,6 +72,7 @@ Added in v2.3.0 - [chainReaderKW](#chainreaderkw) - [chainTaskK](#chaintaskk) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -534,7 +535,7 @@ Added in v2.3.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -723,9 +724,7 @@ Added in v2.4.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types will be merged. +Alias of `flatMap`. **Signature** @@ -737,6 +736,19 @@ export declare const chainW: ( Added in v2.6.7 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => ReaderTask): (ma: ReaderTask) => ReaderTask + (ma: ReaderTask, f: (a: A) => ReaderTask): ReaderTask +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index 26295269b..abbabc84c 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -150,6 +150,7 @@ Added in v2.0.0 - [chainTaskEitherKW](#chaintaskeitherkw) - [chainTaskK](#chaintaskk) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -1317,7 +1318,7 @@ Added in v2.10.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1812,9 +1813,7 @@ Added in v2.10.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1826,6 +1825,25 @@ export declare const chainW: ( Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => ReaderTaskEither): ( + ma: ReaderTaskEither + ) => ReaderTaskEither + (ma: ReaderTaskEither, f: (a: A) => ReaderTaskEither): ReaderTaskEither< + R1 & R2, + E1 | E2, + B + > +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReadonlyArray.ts.md b/docs/modules/ReadonlyArray.ts.md index dcc45e67f..bd7fc74f1 100644 --- a/docs/modules/ReadonlyArray.ts.md +++ b/docs/modules/ReadonlyArray.ts.md @@ -110,6 +110,7 @@ Added in v2.5.0 - [chainRecBreadthFirst](#chainrecbreadthfirst) - [chainRecDepthFirst](#chainrecdepthfirst) - [chainWithIndex](#chainwithindex) + - [flatMap](#flatmap) - [flatten](#flatten) - [traverseWithIndex](#traversewithindex) - [traversing](#traversing) @@ -1249,7 +1250,7 @@ Added in v2.5.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1257,28 +1258,6 @@ Composes computations in sequence, using the return value of one computation to export declare const chain: (f: (a: A) => readonly B[]) => (ma: readonly A[]) => readonly B[] ``` -**Example** - -```ts -import * as RA from 'fp-ts/ReadonlyArray' -import { pipe } from 'fp-ts/function' - -assert.deepStrictEqual( - pipe( - [1, 2, 3], - RA.chain((n) => [`a${n}`, `b${n}`]) - ), - ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] -) -assert.deepStrictEqual( - pipe( - [1, 2, 3], - RA.chain(() => []) - ), - [] -) -``` - Added in v2.5.0 ## chainFirst @@ -1346,6 +1325,43 @@ export declare const chainWithIndex: (f: (i: number, a: A) => readonly B[] Added in v2.7.0 +## flatMap + +Composes computations in sequence, using the return value of one computation to determine the next computation. + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => readonly B[]): (ma: readonly A[]) => readonly B[] + (ma: readonly A[], f: (a: A) => readonly B[]): readonly B[] +} +``` + +**Example** + +```ts +import * as RA from 'fp-ts/ReadonlyArray' +import { pipe } from 'fp-ts/function' + +assert.deepStrictEqual( + pipe( + [1, 2, 3], + RA.flatMap((n) => [`a${n}`, `b${n}`]) + ), + ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] +) +assert.deepStrictEqual( + pipe( + [1, 2, 3], + RA.flatMap(() => []) + ), + [] +) +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/ReadonlyNonEmptyArray.ts.md b/docs/modules/ReadonlyNonEmptyArray.ts.md index e5f772828..be65557be 100644 --- a/docs/modules/ReadonlyNonEmptyArray.ts.md +++ b/docs/modules/ReadonlyNonEmptyArray.ts.md @@ -79,6 +79,7 @@ Added in v2.5.0 - [chain](#chain) - [chainFirst](#chainfirst) - [chainWithIndex](#chainwithindex) + - [flatMap](#flatmap) - [flatten](#flatten) - [traverseWithIndex](#traversewithindex) - [traversing](#traversing) @@ -722,7 +723,7 @@ Added in v2.11.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -732,21 +733,6 @@ export declare const chain: ( ) => (ma: ReadonlyNonEmptyArray) => ReadonlyNonEmptyArray ``` -**Example** - -```ts -import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray' -import { pipe } from 'fp-ts/function' - -assert.deepStrictEqual( - pipe( - [1, 2, 3], - RNEA.chain((n) => [`a${n}`, `b${n}`]) - ), - ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] -) -``` - Added in v2.5.0 ## chainFirst @@ -791,6 +777,34 @@ export declare const chainWithIndex: ( Added in v2.10.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => ReadonlyNonEmptyArray): (ma: ReadonlyNonEmptyArray) => ReadonlyNonEmptyArray + (ma: ReadonlyNonEmptyArray, f: (a: A) => ReadonlyNonEmptyArray): ReadonlyNonEmptyArray +} +``` + +**Example** + +```ts +import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray' +import { pipe } from 'fp-ts/function' + +assert.deepStrictEqual( + pipe( + [1, 2, 3], + RNEA.flatMap((n) => [`a${n}`, `b${n}`]) + ), + ['a1', 'b1', 'a2', 'b2', 'a3', 'b3'] +) +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/State.ts.md b/docs/modules/State.ts.md index 04245f95a..6d78b4358 100644 --- a/docs/modules/State.ts.md +++ b/docs/modules/State.ts.md @@ -34,6 +34,7 @@ Added in v2.0.0 - [sequencing](#sequencing) - [chain](#chain) - [chainFirst](#chainfirst) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequenceArray](#sequencearray) @@ -236,12 +237,12 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** ```ts -export declare const chain: (f: (a: A) => State) => (ma: State) => State +export declare const chain: (f: (a: A) => State) => (ma: State) => State ``` Added in v2.0.0 @@ -259,6 +260,19 @@ export declare const chainFirst: (f: (a: A) => State) => (ma: Sta Added in v2.0.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => State): (ma: State) => State + (ma: State, f: (a: A) => State): State +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index d635e3e87..073c75ce5 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -112,6 +112,7 @@ Added in v2.0.0 - [chainTaskEitherKW](#chaintaskeitherkw) - [chainTaskK](#chaintaskk) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -934,7 +935,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1263,9 +1264,7 @@ Added in v2.10.0 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the environment types and the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1277,6 +1276,24 @@ export declare const chainW: ( Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => StateReaderTaskEither): ( + ma: StateReaderTaskEither + ) => StateReaderTaskEither + ( + ma: StateReaderTaskEither, + f: (a: A) => StateReaderTaskEither + ): StateReaderTaskEither +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/Task.ts.md b/docs/modules/Task.ts.md index ef1d2e915..863ee4fd1 100644 --- a/docs/modules/Task.ts.md +++ b/docs/modules/Task.ts.md @@ -57,6 +57,7 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstIOK](#chainfirstiok) - [chainIOK](#chainiok) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequenceArray](#sequencearray) @@ -387,7 +388,7 @@ Added in v2.0.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -430,6 +431,19 @@ export declare const chainIOK: (f: (a: A) => IO) => (first: Task) => Added in v2.4.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => Task): (ma: Task) => Task + (ma: Task, f: (a: A) => Task): Task +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md index adc800252..958f9ebe2 100644 --- a/docs/modules/TaskEither.ts.md +++ b/docs/modules/TaskEither.ts.md @@ -127,6 +127,7 @@ Added in v2.0.0 - [chainTaskOptionK](#chaintaskoptionk) - [chainTaskOptionKW](#chaintaskoptionkw) - [chainW](#chainw) + - [flatMap](#flatmap) - [flatten](#flatten) - [flattenW](#flattenw) - [traversing](#traversing) @@ -1268,7 +1269,7 @@ Added in v2.10.0 ## chain -Composes computations in sequence, using the return value of one computation to determine the next computation. +Alias of `flatMap`. **Signature** @@ -1497,9 +1498,7 @@ Added in v2.12.3 ## chainW -Less strict version of [`chain`](#chain). - -The `W` suffix (short for **W**idening) means that the error types will be merged. +Alias of `flatMap`. **Signature** @@ -1511,6 +1510,19 @@ export declare const chainW: ( Added in v2.6.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => TaskEither): (ma: TaskEither) => TaskEither + (ma: TaskEither, f: (a: A) => TaskEither): TaskEither +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/docs/modules/TaskOption.ts.md b/docs/modules/TaskOption.ts.md index ebc76bfbc..9633d8a74 100644 --- a/docs/modules/TaskOption.ts.md +++ b/docs/modules/TaskOption.ts.md @@ -84,7 +84,6 @@ Added in v2.10.0 - [matchEW](#matchew) - [matchW](#matchw) - [sequencing](#sequencing) - - [chain](#chain) - [chainEitherK](#chaineitherk) - [chainFirst](#chainfirst) - [chainFirstEitherK](#chainfirsteitherk) @@ -94,6 +93,7 @@ Added in v2.10.0 - [chainNullableK](#chainnullablek) - [chainOptionK](#chainoptionk) - [chainTaskK](#chaintaskk) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequenceArray](#sequencearray) @@ -114,6 +114,7 @@ Added in v2.10.0 - [ap](#ap) - [apFirst](#apfirst) - [apSecond](#apsecond) + - [chain](#chain) - [zero](#zero) --- @@ -826,16 +827,6 @@ Added in v2.10.0 # sequencing -## chain - -**Signature** - -```ts -export declare const chain: (f: (a: A) => TaskOption) => (ma: TaskOption) => TaskOption -``` - -Added in v2.10.0 - ## chainEitherK **Signature** @@ -931,6 +922,19 @@ export declare const chainTaskK: (f: (a: A) => T.Task) => (first: TaskO Added in v2.10.0 +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => TaskOption): (ma: TaskOption) => TaskOption + (ma: TaskOption, f: (a: A) => TaskOption): TaskOption +} +``` + +Added in v2.14.0 + ## flatten **Signature** @@ -1145,6 +1149,18 @@ export declare const apSecond: (second: TaskOption) => (first: TaskOpti Added in v2.10.0 +## chain + +Alias of `flatMap`. + +**Signature** + +```ts +export declare const chain: (f: (a: A) => TaskOption) => (ma: TaskOption) => TaskOption +``` + +Added in v2.10.0 + ## zero **Signature** diff --git a/docs/modules/Tree.ts.md b/docs/modules/Tree.ts.md index 413e11e99..7d4acf04b 100644 --- a/docs/modules/Tree.ts.md +++ b/docs/modules/Tree.ts.md @@ -20,8 +20,6 @@ Added in v2.0.0 - [Extract](#extract) - [extract](#extract) -- [Monad](#monad) - - [chain](#chain) - [constructors](#constructors) - [make](#make) - [of](#of) @@ -47,7 +45,7 @@ Added in v2.0.0 - [Comonad](#comonad) - [Foldable](#foldable) - [Functor](#functor) - - [Monad](#monad-1) + - [Monad](#monad) - [Pointed](#pointed) - [Traversable](#traversable) - [getEq](#geteq) @@ -59,6 +57,8 @@ Added in v2.0.0 - [Forest (type alias)](#forest-type-alias) - [Tree (interface)](#tree-interface) - [sequencing](#sequencing) + - [chain](#chain) + - [flatMap](#flatmap) - [flatten](#flatten) - [traversing](#traversing) - [sequence](#sequence) @@ -94,20 +94,6 @@ export declare const extract: (wa: Tree) => A Added in v2.6.2 -# Monad - -## chain - -Composes computations in sequence, using the return value of one computation to determine the next computation. - -**Signature** - -```ts -export declare const chain: (f: (a: A) => Tree) => (ma: Tree) => Tree -``` - -Added in v2.0.0 - # constructors ## make @@ -512,6 +498,31 @@ Added in v2.0.0 # sequencing +## chain + +Alias of `flatMap`. + +**Signature** + +```ts +export declare const chain: (f: (a: A) => Tree) => (ma: Tree) => Tree +``` + +Added in v2.0.0 + +## flatMap + +**Signature** + +```ts +export declare const flatMap: { + (f: (a: A) => Tree): (ma: Tree) => Tree + (ma: Tree, f: (a: A) => Tree): Tree +} +``` + +Added in v2.14.0 + ## flatten **Signature** diff --git a/src/Array.ts b/src/Array.ts index 669bd5961..a2aa073fe 100644 --- a/src/Array.ts +++ b/src/Array.ts @@ -1586,7 +1586,7 @@ export const ap: (fa: Array) => (fab: Array<(a: A) => B>) => Array = export const flatMap: { (f: (a: A) => Array): (ma: Array) => Array (ma: Array, f: (a: A) => Array): Array -} = dual( +} = /*#__PURE__*/ dual( 2, (ma: Array, f: (a: A) => Array): Array => pipe( diff --git a/src/IO.ts b/src/IO.ts index b733e18c8..1c127d10b 100644 --- a/src/IO.ts +++ b/src/IO.ts @@ -78,7 +78,7 @@ export const of: (a: A) => IO = constant export const flatMap: { (f: (a: A) => IO): (ma: IO) => IO (ma: IO, f: (a: A) => IO): IO -} = dual( +} = /*#__PURE__*/ dual( 2, (ma: IO, f: (a: A) => IO): IO => () => diff --git a/src/IOOption.ts b/src/IOOption.ts index 6884c35b5..2c21441ac 100644 --- a/src/IOOption.ts +++ b/src/IOOption.ts @@ -245,7 +245,7 @@ export const of: (a: A) => IOOption = some export const flatMap: { (f: (a: A) => IOOption): (ma: IOOption) => IOOption (ma: IOOption, f: (a: A) => IOOption): IOOption -} = dual(2, OT.flatMap(I.Monad)) +} = /*#__PURE__*/ dual(2, OT.flatMap(I.Monad)) /** * Alias of `flatMap`. diff --git a/src/Identity.ts b/src/Identity.ts index ee5c88d4d..9734ae22e 100644 --- a/src/Identity.ts +++ b/src/Identity.ts @@ -78,7 +78,7 @@ export const of: (a: A) => Identity = id export const flatMap: { (f: (a: A) => Identity): (ma: Identity) => Identity (ma: Identity, f: (a: A) => Identity): Identity -} = dual(2, (ma: Identity, f: (a: A) => Identity): Identity => f(ma)) +} = /*#__PURE__*/ dual(2, (ma: Identity, f: (a: A) => Identity): Identity => f(ma)) /** * Alias of `flatMap`. diff --git a/src/Option.ts b/src/Option.ts index 4ccabaf3a..8b285cc85 100644 --- a/src/Option.ts +++ b/src/Option.ts @@ -394,7 +394,7 @@ export const Applicative: Applicative1 = { export const flatMap: { (f: (a: A) => Option): (ma: Option) => Option (ma: Option, f: (a: A) => Option): Option -} = dual(2, (ma: Option, f: (a: A) => Option): Option => (isNone(ma) ? none : f(ma.value))) +} = /*#__PURE__*/ dual(2, (ma: Option, f: (a: A) => Option): Option => (isNone(ma) ? none : f(ma.value))) /** * Alias of `flatMap`. diff --git a/src/ReadonlyArray.ts b/src/ReadonlyArray.ts index d397c67ad..a5b7312c1 100644 --- a/src/ReadonlyArray.ts +++ b/src/ReadonlyArray.ts @@ -1511,7 +1511,7 @@ export const ap: (fa: ReadonlyArray) => (fab: ReadonlyArray<(a: A) => B export const flatMap: { (f: (a: A) => ReadonlyArray): (ma: ReadonlyArray) => ReadonlyArray (ma: ReadonlyArray, f: (a: A) => ReadonlyArray): ReadonlyArray -} = dual( +} = /*#__PURE__*/ dual( 2, (ma: ReadonlyArray, f: (a: A) => ReadonlyArray): ReadonlyArray => pipe( diff --git a/src/State.ts b/src/State.ts index f55ba96ad..8715434cc 100644 --- a/src/State.ts +++ b/src/State.ts @@ -100,7 +100,7 @@ export const of: (a: A) => State = (a) => (s) => [a, s] export const flatMap: { (f: (a: A) => State): (ma: State) => State (ma: State, f: (a: A) => State): State -} = dual( +} = /*#__PURE__*/ dual( 2, (ma: State, f: (a: A) => State): State => (s1) => { diff --git a/src/Task.ts b/src/Task.ts index 0c548a7c5..73a4699fd 100644 --- a/src/Task.ts +++ b/src/Task.ts @@ -132,7 +132,7 @@ export const of: (a: A) => Task = (a) => () => Promise.resolve(a) export const flatMap: { (f: (a: A) => Task): (ma: Task) => Task (ma: Task, f: (a: A) => Task): Task -} = dual( +} = /*#__PURE__*/ dual( 2, (ma: Task, f: (a: A) => Task): Task => () => diff --git a/src/TaskOption.ts b/src/TaskOption.ts index 38ca0d6e3..e1a059afe 100644 --- a/src/TaskOption.ts +++ b/src/TaskOption.ts @@ -287,7 +287,7 @@ export const of: (a: A) => TaskOption = some export const flatMap: { (f: (a: A) => TaskOption): (ma: TaskOption) => TaskOption (ma: TaskOption, f: (a: A) => TaskOption): TaskOption -} = dual(2, OT.flatMap(T.Monad)) +} = /*#__PURE__*/ dual(2, OT.flatMap(T.Monad)) /** * Alias of `flatMap`.