Skip to content

Commit

Permalink
docs: add traversing category
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Oct 3, 2022
1 parent 435fe15 commit 5570405
Show file tree
Hide file tree
Showing 58 changed files with 1,894 additions and 1,585 deletions.
53 changes: 28 additions & 25 deletions docs/modules/Array.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ Added in v2.0.0
- [chainRecDepthFirst](#chainrecdepthfirst)
- [chainWithIndex](#chainwithindex)
- [flatten](#flatten)
- [traverseWithIndex](#traversewithindex)
- [traversing](#traversing)
- [sequence](#sequence)
- [traverse](#traverse)
- [traverseWithIndex](#traversewithindex)
- [type lambdas](#type-lambdas)
- [URI](#uri)
- [URI (type alias)](#uri-type-alias)
Expand Down Expand Up @@ -1827,6 +1828,32 @@ assert.deepStrictEqual(flatten([['a'], ['b', 'c'], ['d', 'e', 'f']]), ['a', 'b',

Added in v2.5.0

## traverseWithIndex

Same as [`traverse`](#traverse) but passing also the index to the iterating function.

**Signature**

```ts
export declare const traverseWithIndex: PipeableTraverseWithIndex1<'Array', number>
```

**Example**

```ts
import { traverseWithIndex } from 'fp-ts/Array'
import { Applicative, left, right } from 'fp-ts/lib/Either'
const f = (index: number, x: unknown) =>
typeof x === 'string' ? right(x.toUpperCase() + index) : left(new Error('not a string'))
assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(['a', 'b']), right(['A0', 'B1']))
assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(['a', 5]), left(new Error('not a string')))
```

Added in v2.6.3

# traversing

## sequence

`sequence` takes an `Array` where elements are `HKT<A>` (higher kinded type) and,
Expand Down Expand Up @@ -1890,30 +1917,6 @@ assert.deepStrictEqual(traverse(Applicative)(f)(['a', 5]), left(new Error('not a

Added in v2.6.3

## traverseWithIndex

Same as [`traverse`](#traverse) but passing also the index to the iterating function.

**Signature**

```ts
export declare const traverseWithIndex: PipeableTraverseWithIndex1<'Array', number>
```

**Example**

```ts
import { traverseWithIndex } from 'fp-ts/Array'
import { Applicative, left, right } from 'fp-ts/lib/Either'

const f = (index: number, x: unknown) =>
typeof x === 'string' ? right(x.toUpperCase() + index) : left(new Error('not a string'))
assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(['a', 'b']), right(['A0', 'B1']))
assert.deepStrictEqual(traverseWithIndex(Applicative)(f)(['a', 5]), left(new Error('not a string')))
```

Added in v2.6.3

# type lambdas

## URI
Expand Down
150 changes: 78 additions & 72 deletions docs/modules/Either.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,19 @@ Added in v2.0.0
- [chainW](#chainw)
- [flatten](#flatten)
- [flattenW](#flattenw)
- [traversing](#traversing)
- [sequence](#sequence)
- [sequenceArray](#sequencearray)
- [traverse](#traverse)
- [tuple sequencing](#tuple-sequencing)
- [ApT](#apt)
- [traverseArray](#traversearray)
- [traverseArrayWithIndex](#traversearraywithindex)
- [traverseReadonlyArrayWithIndex](#traversereadonlyarraywithindex)
- [traverseReadonlyNonEmptyArrayWithIndex](#traversereadonlynonemptyarraywithindex)
- [type lambdas](#type-lambdas)
- [URI](#uri)
- [URI (type alias)](#uri-type-alias)
- [utils](#utils)
- [ApT](#apt)
- [ap](#ap)
- [apFirst](#apfirst)
- [apFirstW](#apfirstw)
Expand All @@ -177,14 +182,9 @@ Added in v2.0.0
- [elem](#elem)
- [exists](#exists)
- [extend](#extend)
- [sequenceArray](#sequencearray)
- [swap](#swap)
- [throwError](#throwerror)
- [toError](#toerror)
- [traverseArray](#traversearray)
- [traverseArrayWithIndex](#traversearraywithindex)
- [traverseReadonlyArrayWithIndex](#traversereadonlyarraywithindex)
- [traverseReadonlyNonEmptyArrayWithIndex](#traversereadonlynonemptyarraywithindex)
- [zone of death](#zone-of-death)
- [~~JsonArray~~ (interface)](#jsonarray-interface)
- [~~JsonRecord~~ (interface)](#jsonrecord-interface)
Expand Down Expand Up @@ -1462,6 +1462,8 @@ export declare const flattenW: <E1, E2, A>(mma: Either<E1, Either<E2, A>>) => Ei

Added in v2.11.0

# traversing

## sequence

Evaluate each monadic action in the structure from left to right, and collect the results.
Expand All @@ -1486,6 +1488,18 @@ assert.deepStrictEqual(pipe(E.right(O.none), E.sequence(O.Applicative)), O.none)

Added in v2.6.3

## sequenceArray

Equivalent to `ReadonlyArray#sequence(Applicative)`.

**Signature**

```ts
export declare const sequenceArray: <E, A>(as: readonly Either<E, A>[]) => Either<E, readonly A[]>
```

Added in v2.9.0

## traverse

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.
Expand All @@ -1511,14 +1525,58 @@ assert.deepStrictEqual(pipe(E.right([]), E.traverse(O.Applicative)(RA.head)), O.

Added in v2.6.3

# tuple sequencing
## traverseArray

## ApT
Equivalent to `ReadonlyArray#traverse(Applicative)`.

**Signature**

```ts
export declare const ApT: Either<never, readonly []>
export declare const traverseArray: <E, A, B>(
f: (a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.9.0

## traverseArrayWithIndex

Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.

**Signature**

```ts
export declare const traverseArrayWithIndex: <E, A, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.9.0

## traverseReadonlyArrayWithIndex

Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.

**Signature**

```ts
export declare const traverseReadonlyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.11.0

## traverseReadonlyNonEmptyArrayWithIndex

Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.

**Signature**

```ts
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => Either<E, ReadonlyNonEmptyArray<B>>
```

Added in v2.11.0
Expand Down Expand Up @@ -1547,6 +1605,16 @@ Added in v2.0.0
# utils
## ApT
**Signature**
```ts
export declare const ApT: Either<never, readonly []>
```

Added in v2.11.0

## ap

**Signature**
Expand Down Expand Up @@ -1680,16 +1748,6 @@ export declare const extend: <E, A, B>(f: (wa: Either<E, A>) => B) => (wa: Eithe

Added in v2.0.0

## sequenceArray

**Signature**

```ts
export declare const sequenceArray: <E, A>(as: readonly Either<E, A>[]) => Either<E, readonly A[]>
```

Added in v2.9.0

## swap

Returns a `Right` if is a `Left` (and vice versa).
Expand Down Expand Up @@ -1724,58 +1782,6 @@ export declare function toError(e: unknown): Error

Added in v2.0.0

## traverseArray

**Signature**

```ts
export declare const traverseArray: <E, A, B>(
f: (a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.9.0

## traverseArrayWithIndex

**Signature**

```ts
export declare const traverseArrayWithIndex: <E, A, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.9.0

## traverseReadonlyArrayWithIndex

Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`.

**Signature**

```ts
export declare const traverseReadonlyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: readonly A[]) => Either<E, readonly B[]>
```

Added in v2.11.0

## traverseReadonlyNonEmptyArrayWithIndex

Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`.

**Signature**

```ts
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, E, B>(
f: (index: number, a: A) => Either<E, B>
) => (as: ReadonlyNonEmptyArray<A>) => Either<E, ReadonlyNonEmptyArray<B>>
```

Added in v2.11.0

# zone of death

## ~~JsonArray~~ (interface)
Expand Down
Loading

0 comments on commit 5570405

Please sign in to comment.