Skip to content

Commit 4e16882

Browse files
IO overview in README
1 parent 4f0d555 commit 4e16882

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,30 @@ final match = right.match(
156156
final option = right.toOption();
157157
```
158158

159+
### [IO](./lib/src/io.dart)
160+
Wrapper around an **sync** function. Allows to compose synchronous functions **that never fail**.
161+
162+
```dart
163+
/// Create instance of [IO] from a value
164+
final IO<int> io = IO.of(10);
165+
166+
/// Create instance of [IO] from a sync function
167+
final ioRun = IO(() => 10);
168+
169+
/// Map [int] to [String]
170+
final IO<String> map = io.map((a) => '$a');
171+
172+
/// Extract the value inside [IO] by running its function
173+
final int value = io.run();
174+
175+
/// Chain another [IO] based on the value of the current [IO]
176+
final flatMap = io.flatMap((a) => IO.of(a + 10));
177+
```
178+
159179
### [Task](./lib/src/task.dart)
160-
Wrapper around an async function (`Future`). Allows to compose asynchronous functions **that never fail**.
180+
Wrapper around an **async** function (`Future`). Allows to compose asynchronous functions **that never fail**.
181+
182+
> If you look closely, it's the same as [`IO`](#io) but for **async functions** 💡
161183

162184
```dart
163185
/// Create instance of [Task] from a value

example/src/io/overview.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:fpdart/fpdart.dart';
2+
3+
Future<void> main() async {
4+
/// Create instance of [IO] from a value
5+
final IO<int> io = IO.of(10);
6+
7+
/// Create instance of [IO] from a sync function
8+
final ioRun = IO(() => 10);
9+
10+
/// Map [int] to [String]
11+
final IO<String> map = io.map((a) => '$a');
12+
13+
/// Extract the value inside [IO] by running its function
14+
final int value = io.run();
15+
16+
/// Chain another [IO] based on the value of the current [IO]
17+
final flatMap = io.flatMap((a) => IO.of(a + 10));
18+
}

0 commit comments

Comments
 (0)