From 35b1bb4da573b13db70fdfda6425ebea60427d7f Mon Sep 17 00:00:00 2001 From: "Sahar Rachamim (Kishu)" Date: Tue, 13 Oct 2020 15:26:27 +0300 Subject: [PATCH] Add description & example to sequence in Either --- docs/modules/Either.ts.md | 14 ++++++++++++++ src/Either.ts | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/modules/Either.ts.md b/docs/modules/Either.ts.md index 1500cee4b..1a42b0f1b 100644 --- a/docs/modules/Either.ts.md +++ b/docs/modules/Either.ts.md @@ -440,12 +440,26 @@ Added in v2.6.3 ## sequence +Evaluate each monadic action in the structure from left to right, and collect the results. + **Signature** ```ts export declare const sequence: Sequence2<'Either'> ``` +**Example** + +```ts +import { pipe } from 'fp-ts/function' +import * as E from 'fp-ts/Either' +import * as O from 'fp-ts/Option' + +assert.deepStrictEqual(pipe(E.right(O.some('a')), E.sequence(O.option)), O.some(E.right('a'))) + +assert.deepStrictEqual(pipe(E.right(O.none), E.sequence(O.option)), O.none) +``` + Added in v2.6.3 ## traverse diff --git a/src/Either.ts b/src/Either.ts index 15a69b271..4ff612ade 100644 --- a/src/Either.ts +++ b/src/Either.ts @@ -617,6 +617,23 @@ export const traverse: PipeableTraverse2 = (F: ApplicativeHKT) => > => (isLeft(ta) ? F.of(left(ta.left)) : F.map>(f(ta.right), right)) /** + * Evaluate each monadic action in the structure from left to right, and collect the results. + * + * @example + * import { pipe } from 'fp-ts/function' + * import * as E from 'fp-ts/Either' + * import * as O from 'fp-ts/Option' + * + * assert.deepStrictEqual( + * pipe(E.right(O.some('a')), E.sequence(O.option)), + * O.some(E.right('a')), + * ) + * + * assert.deepStrictEqual( + * pipe(E.right(O.none), E.sequence(O.option)), + * O.none + * ) + * * @category Traversable * @since 2.6.3 */