File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,8 +156,30 @@ final match = right.match(
156156final 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments