combineLatest<R> function

EventSubscriptionBuilder<R> combineLatest<R>(
  1. List<EventSubscriptionBuilder> events,
  2. R combinator(
    1. List events
    )
)

Combines the latest items emitted by the given events into a single EventHandler using the combinator function.

Interactive marble diagram

Consider using the typed version combineLatest2 - combineLatest9.

Example

combineLatest(
 [
   eventManager.on<EventA>(), // emits ['a']
   eventManager.on<EventB>(), // emits ['b']
   eventManager.on<EventC>(), // emits ['c', 'C']
 ],
 (values) => values.join(' '),
).subscribeFunction(print); // prints ['a b c', 'a b C']

Implementation

EventSubscriptionBuilder<R> combineLatest<R>(
  List<EventSubscriptionBuilder<dynamic>> events,
  R Function(List<dynamic> events) combinator,
) {
  if (events.isEmpty) {
    throw ArgumentError.value(
      events,
      'events',
      'Cannot be empty',
    );
  }

  final builder = _CombineLatestEventSubscriptionBuilder<R>(
    combinator: combinator,
    events: events,
  );

  return builder;
}