nullability 1.0.0 copy "nullability: ^1.0.0" to clipboard
nullability: ^1.0.0 copied to clipboard

Provides handy extension to work with nullable types

Features #

Provides the optimized extensions to work with nullable types:

extension NullableX<T extends Object?> on T? {
  @pragma('vm:prefer-inline')
  R? mapNotNull<R>(R? Function(T) callback) {
    return this == null ? null : callback(this as T);
  }
}

extension NullableStringX on String? {
  @pragma('vm:prefer-inline')
  String? get whenNotEmpty {
    final value = this;
    return value != null && value.isNotEmpty ? value : null;
  }

  @pragma('vm:prefer-inline')
  bool get isNotEmpty => this != null && this!.isNotEmpty;

  @pragma('vm:prefer-inline')
  bool get isEmpty => this == null || this!.isEmpty;
}

extension NullableIterable on Iterable? {
  @pragma('vm:prefer-inline')
  bool get isNotEmpty => this != null && this!.isNotEmpty;

  @pragma('vm:prefer-inline')
  bool get isEmpty => this == null || this!.isEmpty;
}
0
likes
150
points
62
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Provides handy extension to work with nullable types

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

More

Packages that depend on nullability