Skip to content

Commit

Permalink
Add description & example to sequence in Either
Browse files Browse the repository at this point in the history
  • Loading branch information
SRachamim authored and gcanti committed Oct 26, 2020
1 parent cae388d commit 35b1bb4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/modules/Either.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,23 @@ export const traverse: PipeableTraverse2<URI> = <F>(F: ApplicativeHKT<F>) => <A,
): HKT<F, Either<E, B>> => (isLeft(ta) ? F.of(left(ta.left)) : F.map<B, Either<E, B>>(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
*/
Expand Down

0 comments on commit 35b1bb4

Please sign in to comment.