New
v1.0.0
- Minimum environment dart sdk to
3.0.0⚠️ (Dart 3️⃣)
environment:
sdk: ">=3.0.0 <4.0.0"
- Added new
ReaderTaskEithertypeReaderTaskEithermodels a complete program usingReaderfor dependency injection,Taskto perform asynchronous computation, andEitherto handle errors 🎯
- Added new
ReaderTasktype Eitherassealedclass (Dart 3️⃣)- You can now use exhaustive pattern matching (
LeftorRight)
- You can now use exhaustive pattern matching (
/// Pattern matching
final match = right.match(
(l) => print('Left($l)'),
(r) => print('Right($r)'),
);
/// or use Dart's pattern matching as well 🤝
final dartMatch = switch (right) {
Left(value: final l) => 'Left($l)',
Right(value: final r) => 'Right($r)',
};
Optionassealedclass (Dart 3️⃣)- You can now use exhaustive pattern matching (
NoneorSome)
- You can now use exhaustive pattern matching (
/// Pattern matching
final match = option.match(
() => print('None'),
(a) => print('Some($a)'),
);
/// or use Dart's pattern matching as well 🤝
final dartMatch = switch (option) {
None() => 'None',
Some(value: final a) => 'Some($a)',
};
- Types marked as
final(noextendsnorimplements) (Dart 3️⃣)UnitReaderStateStateAsyncIOIORefIOOptionIOEitherTaskTaskOptionTaskEitherReaderTaskReaderTaskEither
- Removed
Tuple2, use Dart 3 Records instead (Tuple2(a, b)becomes simply(a, b)🎯) ⚠️ (Dart 3️⃣)- Updated all internal APIs to use records instead of
Tuple2
- Updated all internal APIs to use records instead of
- Major refactoring of
IterableandListextension methods- Improved performance
- Correct return types (
IterableandList) (#65) - Added the following methods
prependAll(Iterable)intersperse(Iterable)difference(Iterable)filterWithIndex(Iterable)
- Fixed the following methods ⚠️
takeWhileRight: ResultingListnow in reversed order as expecteddropWhileRight: ResultingListnow in reversed order as expected
- Updated the following methods ⚠️
foldRight,foldRightWithIndex(List): Changed parameter order incombinefunctionzipWith(Iterable): Changed parameters definition, no more curried
- Renamed the following methods ⚠️
plus→concat(Iterable)- → (on )
/// As extension on [String]
final result = "10".toNumOption; /// `Some(10)`
final result = "10.5".toNumOption; /// `Some(10.5)`
final result = "0xFF".toIntOption; /// `Some(255)`
final result = "10.5".toDoubleOption; /// `Some(10.5)`
final result = "NO".toBoolEither(() => "left"); /// `Left("left")`
/// As functions
final result = toNumOption("10"); /// `Some(10)`
final result = toNumOption("10.5"); /// `Some(10.5)`
final result = toIntOption("0xFF"); /// `Some(255)`
final result = toDoubleOption("10.5"); /// `Some(10.5)`
final result = toBoolEither("NO", () => "left"); /// `Left("left")`
- Changed
dateNow,now,random, andrandomBoolto getter functions
/// Before
Option<T> getRandomOption<T>(T value) => randomBool()
.map((isValid) => isValid ? some(value) : none<T>())
.run();
/// Now
Option<T> getRandomOption<T>(T value) => randomBool
.map((isValid) => isValid ? some(value) : none<T>())
.run();
- Removed
Predicateclass and added extension methods in its place ⚠️
bool isEven(int n) => n % 2 == 0;
bool isDivisibleBy3(int n) => n % 3 == 0;
final isOdd = isEven.negate;
final isEvenAndDivisibleBy3 = isEven.and(isDivisibleBy3);
final isEvenOrDivisibleBy3 = isEven.or(isDivisibleBy3);
final isStringWithEvenLength = isEven.contramap<String>((n) => n.length);
- Updated curry / uncarry extensions ⚠️
- Renamed
currytocurryAllfor functions with 3, 4, 5 parameters - Changed definition of
curryto curry only the first parameter - Changed
uncurryandcurryextension to getter function - Removed
curryanduncurryas functions (use extension method instead) - Added
curryLast(curry last parameter)
- Renamed
int Function(int) subtractCurried(int n1) => (n2) => n1 - n2;
/// Before
subtractCurried.uncurry()(10, 5);
final addFunction = (int a, int b) => a + b;
final add = curry2(addFunction);
[1, 2, 3].map(add(1)); // returns [2, 3, 4]
/// New
subtractCurried.uncurry(10, 5);
final addFunction = (int a, int b) => a + b;
final add = addFunction.curry;
[1, 2, 3].map(add(1)); // returns [2, 3, 4]
[1, 2, 3].map(addFunction.curry(1)); // returns [2, 3, 4]
- Changed
Eqstatic constructors to methodsorand
- Added
xormethod toEq - Moved
DateTimeinstances ofEqasEqstatic members
/// Before
final eq = dateEqYear; // Global
/// Now
final eq = Eq.dateEqYear;
- Added
Eqinstances fornum,int,double,String, andbool
[1, 2, 3].difference(Eq.eqInt, [2, 3, 4]); /// `[1]`
- Added new method to
Eqcontramap
class Parent {
final int value1;
final double value2;
const Parent(this.value1, this.value2);
}
/// Equality for values of type [Parent] based on their `value1` ([int]).
final eqParentInt = Eq.eqInt.contramap<Parent>(
(p) => p.value1,
);
/// Equality for of type [Parent] based on their `value2` ([double]).
final eqParentDouble = Eq.eqDouble.contramap<Parent>(
(p) => p.value2,
);
- Changed
reverseinOrderfrom static constructor to getter method
/// Before
final reversed = Order.reverse(instance);
/// Now
final reversed = instance.reverse;
- Moved
DateTimeinstances ofOrderasOrderstatic members - Added
Orderinstances fornum,int,double - Added new methods to
Orderbetweenclampcontramap
class Parent {
final int value1;
final double value2;
const Parent(this.value1, this.value2);
}
/// Order values of type [Parent] based on their `value1` ([int]).
final orderParentInt = Order.orderInt.contramap<Parent>(
(p) => p.value1,
);
/// Order values of type [Parent] based on their `value2` ([double]).
final orderParentDouble = Order.orderDouble.contramap<Parent>(
(p) => p.value2,
);
- Removed
boolextension (matchandfold), use the ternary operator or pattern matching instead ⚠️
final boolValue = Random().nextBool();
/// Before
final result = boolValue.match<int>(() => -1, () => 1);
final result = boolValue.fold<int>(() => -1, () => 1);
/// Now
final result = boolValue ? 1 : -1;
final result = switch (boolValue) { true => 1, false => -1 };
- Removed global
idandidFuture, useidentityandidentityFutureinstead ⚠️ - Removed global
idFirstandidSecondfunctions ⚠️ - Removed
Composeclass and extension methods ⚠️ - Removed
Magmatypedef ⚠️ - Removed extension methods on nullable types (
toOption,toEither,toTaskOption,toIOEither,toTaskEither,toTaskEitherAsync) ⚠️ - Organized all extensions inside internal
extensionfolder - Updated README