mirror of https://github.com/AMT-Cheif/drift.git
15 lines
423 B
Dart
15 lines
423 B
Dart
import 'dart:async';
|
|
|
|
/// Transforms a stream of lists into a stream of single elements, assuming
|
|
/// that each list is a singleton.
|
|
StreamTransformer<List<T>, T> singleElements<T>() {
|
|
return StreamTransformer.fromHandlers(handleData: (data, sink) {
|
|
try {
|
|
sink.add(data.single);
|
|
} catch (e) {
|
|
sink.addError(
|
|
StateError('Expected exactly one element, but got ${data.length}'));
|
|
}
|
|
});
|
|
}
|