@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 2.12 kB
Source Map (JSON)
{"version":3,"sources":["asynciterable/operators/pluck.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5B,SAAS,OAAO,CAAC,KAAe,EAAE,MAAc;IAC9C,MAAM,MAAM,GAAG,CAAC,CAAM,EAAE,EAAE;QACxB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/B,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE;gBAC5B,WAAW,GAAG,CAAC,CAAC;aACjB;iBAAM;gBACL,OAAO,SAAS,CAAC;aAClB;SACF;QACD,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,GAAG,IAAc;IAEjB,OAAO,SAAS,qBAAqB,CAAC,MAA8B;QAClE,OAAO,GAAG,CACP,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAwC,CACnE,CAAC,MAAM,CAAC,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC","file":"pluck.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { map } from './map';\nimport { OperatorAsyncFunction } from '../../interfaces';\n\nfunction plucker(props: string[], length: number): (x: any) => any {\n const mapper = (x: any) => {\n let currentProp = x;\n for (let i = 0; i < length; i++) {\n const p = currentProp[props[i]];\n if (typeof p !== 'undefined') {\n currentProp = p;\n } else {\n return undefined;\n }\n }\n return currentProp;\n };\n\n return mapper;\n}\n\n/**\n * Maps each source value to its specified nested property.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @template TResult The type of the elements in the result sequence, obtained by the property names.\n * @param {...string[]} args The nested properties to pluck from each source value.\n * @returns {OperatorAsyncFunction<TSource, TResult>} An async-iterable of property values from the source values.\n */\nexport function pluck<TSource, TResult>(\n ...args: string[]\n): OperatorAsyncFunction<TSource, TResult> {\n return function pluckOperatorFunction(source: AsyncIterable<TSource>): AsyncIterableX<TResult> {\n return map<TSource, TResult>(\n (plucker(args, args.length) as any) as (value: TSource) => TResult\n )(source);\n };\n}\n"]}