MCPcopy
hub / github.com/immutable-js/immutable-js / mapFactory

Function mapFactory

src/Operations.js:245–279  ·  view source on GitHub ↗
(collection, mapper, context)

Source from the content-addressed store, hash-verified

243}
244
245export function mapFactory(collection, mapper, context) {
246 const mappedSequence = makeSequence(collection);
247 mappedSequence.size = collection.size;
248 mappedSequence.has = (key) => collection.has(key);
249 mappedSequence.get = (key, notSetValue) => {
250 const v = collection.get(key, NOT_SET);
251 return v === NOT_SET
252 ? notSetValue
253 : mapper.call(context, v, key, collection);
254 };
255 mappedSequence.__iterateUncached = function (fn, reverse) {
256 return collection.__iterate(
257 (v, k, c) => fn(mapper.call(context, v, k, c), k, this) !== false,
258 reverse
259 );
260 };
261 mappedSequence.__iteratorUncached = function (type, reverse) {
262 const iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
263 return new Iterator(() => {
264 const step = iterator.next();
265 if (step.done) {
266 return step;
267 }
268 const entry = step.value;
269 const key = entry[0];
270 return iteratorValue(
271 type,
272 key,
273 mapper.call(context, entry[1], key, collection),
274 step
275 );
276 });
277 };
278 return mappedSequence;
279}
280
281export function reverseFactory(collection, useKeys) {
282 const reversedSequence = makeSequence(collection);

Callers 2

mapFunction · 0.90
mapMethod · 0.85

Calls 7

iteratorValueFunction · 0.90
makeSequenceFunction · 0.85
nextMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
__iterateMethod · 0.45
__iteratorMethod · 0.45

Tested by

no test coverage detected