letIterableOrNone<T extends Object> function
Converts input to Iterable<Option<T>>, returning None on failure.
Supported types:
Implementation
Option<Iterable<Option<T>>> letIterableOrNone<T extends Object>(dynamic input) {
if (input is Outcome) {
return switch (input.rawSync().value) {
Ok(value: final okValue) => letIterableOrNone(
NoStackOverflowWrapper(okValue),
),
Err() => const None(),
};
}
return switch (input is NoStackOverflowWrapper ? input.value : input) {
// Materialize eagerly so the returned iterable is safe to iterate
// multiple times and so a single-pass source (custom Iterable whose
// `.iterator` getter throws after first use) is consumed exactly once.
final Iterable<dynamic> i => Some(
i.map((e) => letOrNone<T>(e)).toList(growable: false),
),
final String s => jsonDecodeOrNone<Iterable<dynamic>>(
s,
).map((i) => i.map((e) => letOrNone<T>(e)).toList(growable: false)),
_ => const None(),
};
}