nullIfEmpty<T> function
T?
nullIfEmpty<T>(
- T value
Returns null if value
is empty, otherwise returns value
.
Implementation
T? nullIfEmpty<T>(T value) {
if (value is String) return value.nullIfEmpty as T?;
if (value is Map) return value.nullIfEmpty as T?;
if (value is Iterable) return value.nullIfEmpty as T?;
if (value is List) return value.nullIfEmpty as T?;
if (value is Set) return value.nullIfEmpty as T?;
if (value is Queue) return value.nullIfEmpty as T?;
return value;
}