Subtheme of barrio
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
1.9 KiB

2 years ago
{"version":3,"file":"pairwise.js","sourceRoot":"","sources":["../../src/operator/pairwise.ts"],"names":[],"mappings":";AACA,yBAAwC,uBAAuB,CAAC,CAAA;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH;IACE,MAAM,CAAC,mBAAW,EAAE,CAAC,IAAI,CAAuB,CAAC;AACnD,CAAC;AAFe,gBAAQ,WAEvB,CAAA","sourcesContent":["import { Observable } from '../Observable';\nimport { pairwise as higherOrder } from '../operators/pairwise';\n\n/**\n * Groups pairs of consecutive emissions together and emits them as an array of\n * two values.\n *\n * <span class=\"informal\">Puts the current value and previous value together as\n * an array, and emits that.</span>\n *\n * <img src=\"./img/pairwise.png\" width=\"100%\">\n *\n * The Nth emission from the source Observable will cause the output Observable\n * to emit an array [(N-1)th, Nth] of the previous and the current value, as a\n * pair. For this reason, `pairwise` emits on the second and subsequent\n * emissions from the source Observable, but not on the first emission, because\n * there is no previous value in that case.\n *\n * @example <caption>On every click (starting from the second), emit the relative distance to the previous click</caption>\n * var clicks = Rx.Observable.fromEvent(document, 'click');\n * var pairs = clicks.pairwise();\n * var distance = pairs.map(pair => {\n * var x0 = pair[0].clientX;\n * var y0 = pair[0].clientY;\n * var x1 = pair[1].clientX;\n * var y1 = pair[1].clientY;\n * return Math.sqrt(Math.pow(x0 - x1, 2) + Math.pow(y0 - y1, 2));\n * });\n * distance.subscribe(x => console.log(x));\n *\n * @see {@link buffer}\n * @see {@link bufferCount}\n *\n * @return {Observable<Array<T>>} An Observable of pairs (as arrays) of\n * consecutive values from the source Observable.\n * @method pairwise\n * @owner Observable\n */\nexport function pairwise<T>(this: Observable<T>): Observable<[T, T]> {\n return higherOrder()(this) as Observable<[T, T]>;\n}\n"]}