MCPcopy Index your code
hub / github.com/immutable-js/immutable-js / flipFactory

Function flipFactory

src/Operations.js:208–243  ·  view source on GitHub ↗
(collection)

Source from the content-addressed store, hash-verified

206 cacheResultThrough;
207
208export function flipFactory(collection) {
209 const flipSequence = makeSequence(collection);
210 flipSequence._iter = collection;
211 flipSequence.size = collection.size;
212 flipSequence.flip = () => collection;
213 flipSequence.reverse = function () {
214 const reversedSequence = collection.reverse.apply(this); // super.reverse()
215 reversedSequence.flip = () => collection.reverse();
216 return reversedSequence;
217 };
218 flipSequence.has = (key) => collection.includes(key);
219 flipSequence.includes = (key) => collection.has(key);
220 flipSequence.cacheResult = cacheResultThrough;
221 flipSequence.__iterateUncached = function (fn, reverse) {
222 return collection.__iterate((v, k) => fn(k, v, this) !== false, reverse);
223 };
224 flipSequence.__iteratorUncached = function (type, reverse) {
225 if (type === ITERATE_ENTRIES) {
226 const iterator = collection.__iterator(type, reverse);
227 return new Iterator(() => {
228 const step = iterator.next();
229 if (!step.done) {
230 const k = step.value[0];
231 step.value[0] = step.value[1];
232 step.value[1] = k;
233 }
234 return step;
235 });
236 }
237 return collection.__iterator(
238 type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
239 reverse
240 );
241 };
242 return flipSequence;
243}
244
245export function mapFactory(collection, mapper, context) {
246 const mappedSequence = makeSequence(collection);

Callers 2

flipFunction · 0.90
reverseFactoryFunction · 0.85

Calls 7

makeSequenceFunction · 0.85
nextMethod · 0.80
reverseMethod · 0.65
includesMethod · 0.65
hasMethod · 0.65
__iterateMethod · 0.45
__iteratorMethod · 0.45

Tested by

no test coverage detected