Skip to content

Commit cd47d3b

Browse files
authored
Merge pull request #15 from adinvadim/patch-1
Update async.md, replace deprecated array.array.sequence
2 parents b30963d + de5ca06 commit cd47d3b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/async.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ Promise.all([Promise.resolve(1), Promise.resolve(2)]).then(console.log); // [1,
5151
With `Task`s you can achieve the same using `sequence`. Both the `Promise.all` and the `sequence` approach run in parallel and wait until all results have arrived before they proceed.
5252

5353
```ts
54-
import { array, task } from "fp-ts";
54+
import { task } from "fp-ts";
5555

5656
const tasks = [task.of(1), task.of(2)];
57-
array.array.sequence(task.task)(tasks)().then(console.log); // [ 1, 2 ]
57+
task.sequenceArray(tasks)().then(console.log); // [ 1, 2 ]
5858
```
5959

6060
## Run a list of tasks in sequence
6161

6262
If you need to run a list of `Task`s in sequence, i.e. you have to wait for one `Task` to finish before you run the second `Task`, you can use the `taskSeq` instance.
6363

6464
```ts
65-
import { array, task } from "fp-ts";
65+
import { task } from "fp-ts";
6666
import { pipe } from "fp-ts/function";
6767

6868
const log = <A>(x: A) => {
@@ -76,10 +76,10 @@ const tasks = [
7676
];
7777

7878
// Parallel: logs 'second' then 'first'
79-
array.array.sequence(task.task)(tasks)();
79+
task.sequenceArray(tasks)();
8080

8181
// Sequential: logs 'first' then 'second'
82-
array.array.sequence(task.taskSeq)(tasks)();
82+
task.sequenceSeqArray(tasks)();
8383
```
8484

8585
## Work with tasks with different type
@@ -88,10 +88,10 @@ array.array.sequence(task.taskSeq)(tasks)();
8888

8989
<!-- prettier-ignore-start -->
9090
```ts
91-
import { array, task } from "fp-ts";
91+
import { task } from "fp-ts";
9292

9393
const tasks = [task.of(1), task.of("hello")];
94-
array.array.sequence(task.task)(tasks);
94+
task.sequenceArray(tasks);
9595
// ~~~~~ Argument of type '(Task<number> | Task<string>)[]' is not assignable to parameter of type 'Task<number>[]'.
9696
// Type 'Task<number> | Task<string>' is not assignable to type 'Task<number>'.
9797
// Type 'Task<string>' is not assignable to type 'Task<number>'.
@@ -104,9 +104,9 @@ We can use `sequenceT` or `sequenceS` instead.
104104
```ts
105105
import { apply, task } from "fp-ts";
106106

107-
apply.sequenceT(task.task)(task.of(1), task.of("hello")); // type is task.Task<[number, string]>
107+
apply.sequenceT(task.ApplyPar)(task.of(1), task.of("hello")); // type is task.Task<[number, string]>
108108

109-
apply.sequenceS(task.task)({ a: task.of(1), b: task.of("hello") }); // type is task.Task<{ a: number; b: string; }>
109+
apply.sequenceS(task.ApplyPar)({ a: task.of(1), b: task.of("hello") }); // type is task.Task<{ a: number; b: string; }>
110110
```
111111

112112
## Work with a list of dependent tasks
@@ -129,7 +129,7 @@ pipe(
129129
If you have a list of items that you need to `map` over before running them in `sequence`, you can use `traverse`, which is a shortcut for doing both operations in one step.
130130

131131
```ts
132-
import { array, task } from "fp-ts";
132+
import { task } from "fp-ts";
133133
import { access, constants } from "fs";
134134

135135
const checkPathExists = (path: string) => () =>
@@ -139,7 +139,7 @@ const checkPathExists = (path: string) => () =>
139139

140140
const items = ["/bin", "/no/real/path"];
141141

142-
array.array.traverse(task.task)(items, checkPathExists)().then(console.log); // [ { path: '/bin', exists: true }, { path: '/no/real/path', exists: false } ]
142+
task.traverseArray(items, checkPathExists)().then(console.log); // [ { path: '/bin', exists: true }, { path: '/no/real/path', exists: false } ]
143143
```
144144

145145
## Comparison with `Promise` methods

0 commit comments

Comments
 (0)