8000 simplify mapKeys and add mapEntries · powercoder23/immutable-js@7c71505 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c71505

Browse files
committed
simplify mapKeys and add mapEntries
1 parent a660faf commit 7c71505

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

dist/Immutable.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,20 @@ declare module 'immutable' {
473473
thisArg?: any
474474
): Sequence<M, V>;
475475

476+
/**
477+
* Returns a new sequence with entries ([key, value] tuples) passed through
478+
* a `mapper` function.
479+
*
480+
* Sequence({ a: 1, b: 2 })
481+
* .mapEntries(([k, v]) => [k.toUpperCase(), v * 2])
482+
* // { A: 2, B: 4 }
483+
*
484+
*/
485+
mapEntries<KM, VM>(
486+
mapper: (entry?: /*(K, V)*/Array<any>, index?: number, seq?: Sequence<K, V>) => /*(KM, VM)*/Array<any>,
487+
thisArg?: any
488+
): Sequence<KM, VM>;
489+
476490
/**
477491
* Returns a new sequence with only the entries for which the `predicate`
478492
* function returns true.

dist/Immutable.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,10 @@ var $Sequence = Sequence;
480480
return mappedSequence;
481481
},
482482
mapKeys: function(mapper, thisArg) {
483-
var sequence = this;
484-
var mappedSequence = sequence.__makeSequence();
485-
mappedSequence.length = sequence.length;
486-
mappedSequence.__iterateUncached = function(fn, reverse) {
487-
var $__0 = this;
488-
return sequence.__iterate((function(v, k, c) {
489-
return fn(v, mapper.call(thisArg, k, v, c), $__0) !== false;
490-
}), reverse);
491-
};
492-
return mappedSequence;
483+
return this.flip().map(mapper, thisArg).flip();
484+
},
485+
mapEntries: function(mapper, thisArg) {
486+
return this.entrySeq().map(mapper, thisArg).fromEntrySeq();
493487
},
494488
filter: function(predicate, thisArg) {
495489
return filterFactory(this, predicate, thisArg, true);

0 commit comments

Comments
 (0)
0