v0.4.1
- New methods for
Option
type (thanks to tim-smart 🎉)flatMapNullable
flatMapThrowable
final option = Option.of(10);
option.flatMapNullable((a) => a + 1); /// 👈 `Some(11)`
option.flatMapThrowable((a) => a + 1); /// 👈 `Some(11)`
option.flatMapNullable<int>((a) => null); /// 👈 `None()`
option.flatMapThrowable<int>((a) => throw "fail"); /// 👈 `None()`
- Improved support
fromJson
forOption
type (thanks [again] to tim-smart 🎉)- Allow for decoding of non-primitive types (with custom
fromJson
constructors)
- Allow for decoding of non-primitive types (with custom
/// `fromJson` on `DateTime` with `Option` type
final now = DateTime.now();
Option<DateTime>.fromJson(now.toIso8601String(), (a) => DateTime.parse(a as String)); /// 👈 `Some(now)`
Option<DateTime>.fromJson("fail", (a) => DateTime.parse(a as String)); /// 👈 `None()`
- New extension methods for
Map
(thanks [once again] to tim-smart 🎉)extract
extractMap
final map = <String, dynamic>{'a': 1, 'b': 2, 'c': 3, 'd': 4};
map.extract<int>('b'); /// 👈 `Some(2)`
map.extract<String>('b'); /// 👈 `None()`, not of type `String` ⚠️
final map = <String, dynamic>{'a': 1};
map.extractMap('a'); /// 👈 `None()`, not a `Map`
final map = <String, dynamic>{'a': {'b': 2} };
map.extractMap('a'); /// 👈 `Some({'b': 2})`
Option.of
andOption.none
factoriesconst
(thanks to f-person 🎉)
Note: People who have the prefer_const_constructors lint enabled will notice a warning to use
const
🤝
- New
managing_imports
example (thanks to RandalSchwartz 🎉) - Updated README introduction