UNPKG

@iterable-iterator/map

Version:

Iterable mapping functions for JavaScript

1 lines 1.81 kB
{"version":3,"file":"index.cjs","sources":["../src/map.js","../src/pick.js","../src/starmap.js"],"sourcesContent":["/**\n * Applies a given callable to each of the elements of the input iterable.\n *\n * @example\n * // return [ 0 , 1 , 4 , 9 ]\n * list( map( x => x**2 , range( 4 ) ) ) ;\n *\n * @param {Function} callable - The callable to use.\n * @param {Iterable} iterable - The input iterable.\n * @returns {IterableIterator}\n */\nexport default function* map(callable, iterable) {\n\tfor (const item of iterable) {\n\t\tyield callable(item);\n\t}\n}\n","/**\n * Yields some of the properties of the input object. The properties to yield\n * are designated by the input iterable.\n *\n * @example\n * // returns [ 'a' , 'e' , 'c' ]\n * list( pick( 'abcde' , [ 0 , 4 , 2 ] ) ) ;\n *\n * @param {Object} object - The input object.\n * @param {Iterable} iterable - The input iterable.\n * @returns {IterableIterator}\n */\nexport default function* pick(object, iterable) {\n\tfor (const key of iterable) {\n\t\tyield object[key];\n\t}\n}\n","/**\n * Same as {@link map} but allows multiple arguments callable functions.\n *\n * @example\n * // return [ 0 , 1 , 4 , 9 ]\n * list( starmap( ( x , y ) => x*y , zip( range( 4 ) , range( 4 ) ) ) ;\n *\n * @param {Function} callable - The callable to use.\n * @param {Iterable} iterable - The input iterable.\n * @returns {Iterator}\n */\nexport default function* starmap(callable, iterable) {\n\tfor (const args of iterable) {\n\t\tyield callable(...args);\n\t}\n}\n"],"names":["map","callable","iterable","item","pick","object","key","starmap","args"],"mappings":"o1BAWyBA,YAAAA,EAAIC,EAAUC,gGACnBA,0CAClB,OADUC,mBACJF,EAASE,GAFF,0FCCUC,YAAAA,EAAKC,EAAQH,gGACnBA,0CACjB,OADUI,mBACJD,EAAOC,GAFA,0FCDUC,YAAAA,EAAQN,EAAUC,gGACvBA,0CAClB,OADUM,mBACJP,eAAYO,GAFL"}