1 |
- {"version":3,"file":"partition.js","sourceRoot":"","sources":["../../src/operators/partition.ts"],"names":[],"mappings":";AAAA,oBAAoB,aAAa,CAAC,CAAA;AAClC,uBAAuB,UAAU,CAAC,CAAA;AAIlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,mBAA6B,SAA+C,EAC/C,OAAa;IACxC,MAAM,CAAC,UAAC,MAAqB,IAAK,OAAA;QAChC,eAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC;QAClC,eAAM,CAAC,SAAG,CAAC,SAAS,EAAE,OAAO,CAAQ,CAAC,CAAC,MAAM,CAAC;KACb,EAHD,CAGC,CAAC;AACtC,CAAC;AANe,iBAAS,YAMxB,CAAA","sourcesContent":["import { not } from '../util/not';\nimport { filter } from './filter';\nimport { Observable } from '../Observable';\nimport { UnaryFunction } from '../interfaces';\n\n/**\n * Splits the source Observable into two, one with values that satisfy a\n * predicate, and another with values that don't satisfy the predicate.\n *\n * <span class=\"informal\">It's like {@link filter}, but returns two Observables:\n * one like the output of {@link filter}, and the other with values that did not\n * pass the condition.</span>\n *\n * <img src=\"./img/partition.png\" width=\"100%\">\n *\n * `partition` outputs an array with two Observables that partition the values\n * from the source Observable through the given `predicate` function. The first\n * Observable in that array emits source values for which the predicate argument\n * returns true. The second Observable emits source values for which the\n * predicate returns false. The first behaves like {@link filter} and the second\n * behaves like {@link filter} with the predicate negated.\n *\n * @example <caption>Partition click events into those on DIV elements and those elsewhere</caption>\n * var clicks = Rx.Observable.fromEvent(document, 'click');\n * var parts = clicks.partition(ev => ev.target.tagName === 'DIV');\n * var clicksOnDivs = parts[0];\n * var clicksElsewhere = parts[1];\n * clicksOnDivs.subscribe(x => console.log('DIV clicked: ', x));\n * clicksElsewhere.subscribe(x => console.log('Other clicked: ', x));\n *\n * @see {@link filter}\n *\n * @param {function(value: T, index: number): boolean} predicate A function that\n * evaluates each value emitted by the source Observable. If it returns `true`,\n * the value is emitted on the first Observable in the returned array, if\n * `false` the value is emitted on the second Observable in the array. The\n * `index` parameter is the number `i` for the i-th source emission that has\n * happened since the subscription, starting from the number `0`.\n * @param {any} [thisArg] An optional argument to determine the value of `this`\n * in the `predicate` function.\n * @return {[Observable<T>, Observable<T>]} An array with two Observables: one\n * with values that passed the predicate, and another with values that did not\n * pass the predicate.\n * @method partition\n * @owner Observable\n */\nexport function partition<T>(predicate: (value: T, index: number) => boolean,\n thisArg?: any): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {\n return (source: Observable<T>) => [\n filter(predicate, thisArg)(source),\n filter(not(predicate, thisArg) as any)(source)\n ] as [Observable<T>, Observable<T>];\n}\n"]}
|