UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.1 kB
{"version":3,"sources":["iterable/operators/pluck.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGpC,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,CAAmB,GAAG,IAAc;IACvD,OAAO,SAAS,qBAAqB,CAAC,MAAyB;QAC7D,OAAO,IAAI,WAAW,CACpB,MAAM,EACL,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAwC,CACnE,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","file":"pluck.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { MapIterable } from './map';\nimport { OperatorFunction } 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 iterable of property values from the source values.\n */\nexport function pluck<TSource, TResult>(...args: string[]): OperatorFunction<TSource, TResult> {\n return function pluckOperatorFunction(source: Iterable<TSource>): IterableX<TResult> {\n return new MapIterable<TSource, TResult>(\n source,\n (plucker(args, args.length) as any) as (value: TSource) => TResult\n );\n };\n}\n"]}