885f728a87fecbd3f75fbe6936605a71898c34dedc19b4b7ba3f11f0797c3fe084b9c189badc3437c7665f5d58f7d83c047aa8317027858d2493c6cbd0db38 1.5 KB

1234567891011121314151617181920212223242526272829
  1. import { ObservableInputTuple, OperatorFunction, Cons } from '../types';
  2. import { zip } from './zip';
  3. /**
  4. * Subscribes to the source, and the observable inputs provided as arguments, and combines their values, by index, into arrays.
  5. *
  6. * What is meant by "combine by index": The first value from each will be made into a single array, then emitted,
  7. * then the second value from each will be combined into a single array and emitted, then the third value
  8. * from each will be combined into a single array and emitted, and so on.
  9. *
  10. * This will continue until it is no longer able to combine values of the same index into an array.
  11. *
  12. * After the last value from any one completed source is emitted in an array, the resulting observable will complete,
  13. * as there is no way to continue "zipping" values together by index.
  14. *
  15. * Use-cases for this operator are limited. There are memory concerns if one of the streams is emitting
  16. * values at a much faster rate than the others. Usage should likely be limited to streams that emit
  17. * at a similar pace, or finite streams of known length.
  18. *
  19. * In many cases, authors want `combineLatestWith` and not `zipWith`.
  20. *
  21. * @param otherInputs other observable inputs to collate values from.
  22. * @return A function that returns an Observable that emits items by index
  23. * combined from the source Observable and provided Observables, in form of an
  24. * array.
  25. */
  26. export function zipWith<T, A extends readonly unknown[]>(...otherInputs: [...ObservableInputTuple<A>]): OperatorFunction<T, Cons<T, A>> {
  27. return zip(...otherInputs);
  28. }