-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
3,174 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:fpdart/fpdart.dart'; | ||
|
||
void main() { | ||
/// "a40" is invalid 💥 | ||
final inputValues = ["10", "20", "30", "a40"]; | ||
|
||
/// Verify that all the values can be converted to [int] 🔐 | ||
/// | ||
/// If **any** of them is invalid, then the result is [None] 🙅♂️ | ||
final traverseOption = inputValues.traverseOption( | ||
(a) => Option.tryCatch( | ||
/// If `a` does not contain a valid integer literal a [FormatException] is thrown | ||
() => int.parse(a), | ||
), | ||
); | ||
|
||
print(traverseOption); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:fpdart/fpdart.dart'; | ||
|
||
void main() { | ||
final inputValues = ["10", "20", "30", "40"]; | ||
|
||
/// Using `traverse` = `map` + `sequence` 🪄 | ||
final traverseOption = inputValues.traverseOption( | ||
(a) => Option.tryCatch(() => int.parse(a)), | ||
); | ||
|
||
/// Using `sequence`, same as the above with `traverse` 🪄 | ||
final sequenceOption = inputValues | ||
.map((a) => Option.tryCatch(() => int.parse(a))) | ||
.sequenceOption(); | ||
|
||
/// `Some([10, 20, 30, 40])` - Same ☑️ | ||
print(traverseOption); | ||
|
||
/// `Some([10, 20, 30, 40])` - Same ☑️ | ||
print(sequenceOption); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.