import 'package:drift/drift.dart'; extension ExpandQuery on Selectable { /// Expands this selectable by the [expand] function. /// /// Each entry emitted by this [Selectable] will be transformed by the /// [expander] and then emitted to the selectable returned. Selectable expand(Iterable Function(T) expander) { return _ExpandedSelectable(this, expander); } } class _ExpandedSelectable extends Selectable { final Selectable _source; final Iterable Function(S) expander; _ExpandedSelectable(this._source, this.expander); @override Future> get() { return _source.get().then(_mapResults); } @override Stream> watch() { return _source.watch().map(_mapResults); } List _mapResults(List results) => results.expand(expander).toList(); }