normalizeGeneratorOutput function
Converts Future, Iterable, or String to a normalized output.
Handles various return types from generators and converts them to a consistent format: an Iterable of non-empty strings.
@param value The value to normalize @return A Future that resolves to an Iterable of normalized strings @throws ArgumentError if the value cannot be normalized
Implementation
Future<Iterable<String>> normalizeGeneratorOutput(Object? value) async {
if (value == null) {
return Future<Iterable<String>>.value(const Iterable<String>.empty());
} else if (value is Future) {
return value.then(normalizeGeneratorOutput);
} else if (value is String) {
value = <String>[value];
}
if (value is Iterable) {
return value
.where((dynamic e) => e != null)
.map((dynamic e) {
if (e is String) {
return e.trim();
}
throw _argError(e as Object);
})
.where((String e) => e.isNotEmpty);
}
throw _argError(value);
}