Skip to content

Commit

Permalink
Update example and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
san-smith committed Jun 3, 2022
1 parent ad2f24b commit 83887a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [0.3.0] - 03.05.2022

Added new methods to `Option` and `Result`.

Option:

- `flatMap` - returns None or calls `f` with the wrapped value and returns `Some(f(value))`;
- `filter` - returns None if the option is None or predicate returns false, otherwise returns Some.

Result:

- `flatMap` - calls `f` if the result is `Ok`, otherwise returns the `Err` value of self;
- `flatMapErr` - Calls `f` if the result is `Err`, otherwise returns the `Ok` value of self.

## [0.2.1] - 31.05.2022

Restricted the parameterized type E for tryCatch and asyncTryCatch.
Expand Down
11 changes: 5 additions & 6 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import 'dart:math';
import 'package:dfp/dfp.dart';

void main() async {
final str = Option.fromNullable(stdin.readLineSync());
final number = Option.flatten(
str.map((value) => Option.fromNullable(double.tryParse(value))),
);
final fixed = number
final number = fromNullable(stdin.readLineSync())
.flatMap((value) => fromNullable(double.tryParse(value)))
.map(sin)
.filter((value) => value >= 0)
.map((value) => value * 2)
.map((value) => value.abs().toStringAsFixed(2));
print(fixed.toNullable());

print(number.toNullable());
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dfp
description: A library for typed functional programming in Dart, inspired by Rust.
version: 0.2.1
version: 0.3.0
repository: https://github.com/san-smith/dfp

environment:
Expand Down

0 comments on commit 83887a6

Please sign in to comment.