Class Zip
Represents an operator that combines values from the source sequences whenever all of the sequences have produced an element.
Zip
combines the items from each sequence in strict sequential order. It will combine the first item emitted by sequence #1 with the first item emitted by sequence #2; then the second item emitted by sequence #1 with the second item emitted by sequence #2, and so forth, regardless of the timing of arrival of the values. It will only emit as many values as the number of values in the shortest sequence.
Warning
Zip
will continuously store unpaired values from all source sequences, with no limit to the buffer size. This means that if one source sequence produces a much larger number of values than the other sequences, memory usage will continue to grow unbounded. In general, Zip
should be used only when there is a known fixed relationship between number of elements in each of the source sequences.
Examples
Use Zip
to combine the output of two or more sequences together in strict sequential order.
Combine Processing Results
Use Zip
to combine separate processing branches from a single source into a composite result.
Combine Related Events
Use Zip
to pair events which are logically related even though they might arrive far apart in time (e.g. request/response pairs from a server, or pairing camera frames with frame trigger event onsets).
Note
This example requires the Bonsai.Arduino
, Bonsai.Vision
and Bonsai.Vision.Design
packages to be installed.
Sample Preloaded Sequences
Use Zip
to "sample" from a source sequence where all elements are available up front, using a time- or event-based trigger sequence.
Warning
This approach is best suited for text- or numeric-based sequences as Zip
will buffer all available elements with no limit to buffer size.
Alternative
Use WithLatestFrom
or CombineLatest
to combine sequences when their relationship is not well defined.
Higher-order operator
Zip
also works as a higher-order operator, so it can take as input a sequence of observable sequences. In this case, it will subscribe to each of the source sequences and start collecting all emitted values from each sequence. As soon as the outer sequence terminates, it will start reactively combining values in sequential order, just as in the case of using Zip
with a fixed number of inputs.
The higher-order variant can be useful occasionally, for example when combining frames from an unknown number of videos in a folder, but should be used with care and awareness that reactive pairing only starts after the outer sequence terminates, which means its use should be avoided with infinite sequences.
[Combinator]
public class Zip
- Inheritance
-
Zip
- Inherited Members
Methods
- Process<TSource>(IObservable<IObservable<TSource>>)
Merges elements from all inner observable sequences into one observable sequence by emitting a list with the elements of each sequence whenever all of the sequences have produced a new element.
- Process<TSource>(IObservable<TSource>, IObservable<TSource>, params IObservable<TSource>[])
Merges the specified sources into one observable sequence by emitting a list with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2>(IObservable<TSource1>, IObservable<TSource2>)
Merges the specified sources into one observable sequence by emitting a pair with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2, TSource3>(IObservable<TSource1>, IObservable<TSource2>, IObservable<TSource3>)
Merges the specified sources into one observable sequence by emitting a triple with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2, TSource3, TSource4>(IObservable<TSource1>, IObservable<TSource2>, IObservable<TSource3>, IObservable<TSource4>)
Merges the specified sources into one observable sequence by emitting a quadruple with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2, TSource3, TSource4, TSource5>(IObservable<TSource1>, IObservable<TSource2>, IObservable<TSource3>, IObservable<TSource4>, IObservable<TSource5>)
Merges the specified sources into one observable sequence by emitting a quintuple with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6>(IObservable<TSource1>, IObservable<TSource2>, IObservable<TSource3>, IObservable<TSource4>, IObservable<TSource5>, IObservable<TSource6>)
Merges the specified sources into one observable sequence by emitting a sextuple with the elements of the observable sequences whenever all of the sequences have produced a new element.
- Process<TSource1, TSource2, TSource3, TSource4, TSource5, TSource6, TSource7>(IObservable<TSource1>, IObservable<TSource2>, IObservable<TSource3>, IObservable<TSource4>, IObservable<TSource5>, IObservable<TSource6>, IObservable<TSource7>)
Merges the specified sources into one observable sequence by emitting a septuple with the elements of the observable sequences whenever all of the sequences have produced a new element.