majro update
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
extension NullableX<T> on T? {
|
||||
extension NullableX<T extends Object?> on T? {
|
||||
@pragma('vm:prefer-inline')
|
||||
R? mapNotNull<R>(R? Function(T) callback) {
|
||||
// ignore: null_check_on_nullable_type_parameter validated
|
||||
return (this != null) ? callback(this!) : null;
|
||||
// We can simplify this by using the null-aware operator
|
||||
return this != null ? callback(this as T) : null;
|
||||
}
|
||||
}
|
||||
|
||||
extension NullableStringX on String? {
|
||||
@pragma('vm:prefer-inline')
|
||||
String? get whenNotEmpty => (this?.isNotEmpty ?? false) ? this : null;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
bool get isNotEmpty => this?.isNotEmpty ?? false;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
bool get isEmpty => this?.isEmpty ?? true;
|
||||
}
|
||||
|
||||
extension NullableIterable on Iterable? {
|
||||
@pragma('vm:prefer-inline')
|
||||
bool get isNotEmpty => this?.isNotEmpty ?? false;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
bool get isEmpty => this?.isEmpty ?? true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user