Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba83705

Browse filesBrowse files
committed
fix lastIndexOf, move keyed methods to KeyedSeq, add keyOf to mirror indexOf
1 parent f3957c2 commit ba83705
Copy full SHA for ba83705

File tree

Expand file treeCollapse file tree

5 files changed

+134
-94
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+134
-94
lines changed

‎dist/immutable.d.ts

Copy file name to clipboardExpand all lines: dist/immutable.d.ts
+28-18Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,6 @@ declare module 'immutable' {
463463
context?: any
464464
): /*this*/Iterable<K, V>;
465465

466-
/**
467-
* Returns the key for which the `predicate` returns true.
468-
*/
469-
findKey(
470-
predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
471-
context?: any
472-
): K;
473-
474466
/**
475467
* Returns the last value for which the `predicate` returns true.
476468
*
@@ -482,16 +474,6 @@ declare module 'immutable' {
482474
notSetValue?: V
483475
): V;
484476

485-
/**
486-
* Returns the last key for which the `predicate` returns true.
487-
*
488-
* Note: `predicate` will be called for each entry in reverse.
489-
*/
490-
findLastKey(
491-
predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
492-
context?: any
493-
): K;
494-
495477
/**
496478
* The first value in the Iterable.
497479
*/
@@ -775,6 +757,34 @@ declare module 'immutable' {
775757
*/
776758
flip(): /*this*/KeyedIterable<V, K>;
777759

760+
/**
761+
* Returns the key for which the `predicate` returns true.
762+
*/
763+
findKey(
764+
predicate: (value?: V, key?: K, iter?: /*this*/KeyedIterable<K, V>) => boolean,
765+
context?: any
766+
): K;
767+
768+
/**
769+
* Returns the last key for which the `predicate` returns true.
770+
*
771+
* Note: `predicate` will be called for each entry in reverse.
772+
*/
773+
findLastKey(
774+
predicate: (value?: V, key?: K, iter?: /*this*/KeyedIterable<K, V>) => boolean,
775+
context?: any
776+
): K;
777+
778+
/**
779+
* Returns the key associated with the search value, or undefined.
780+
*/
781+
keyOf(searchValue: V): K;
782+
783+
/**
784+
* Returns the last key associated with the search value, or undefined.
785+
*/
786+
lastKeyOf(searchValue: V): K;
787+
778788
/**
779789
* Returns a new KeyedIterable of the same type with entries
780790
* ([key, value] tuples) passed through a `mapper` function.

‎dist/immutable.js

Copy file name to clipboardExpand all lines: dist/immutable.js
+28-19Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -491,22 +491,9 @@ var $Iterable = Iterable;
491491
filterNot: function(predicate, context) {
492492
return this.filter(not(predicate), context);
493493
},
494-
findKey: function(predicate, context) {
495-
var foundKey;
496-
this.__iterate((function(v, k, c) {
497-
if (predicate.call(context, v, k, c)) {
498-
foundKey = k;
499-
return false;
500-
}
501-
}));
502-
return foundKey;
503-
},
504494
findLast: function(predicate, context, notSetValue) {
505495
return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
506496
},
507-
findLastKey: function(predicate, context) {
508-
return this.toKeyedSeq().reverse().findKey(predicate, context);
509-
},
510497
first: function() {
511498
return this.find(returnTrue);
512499
},
@@ -658,6 +645,27 @@ var KeyedIterable = function KeyedIterable(value) {
658645
flip: function() {
659646
return reify(this, flipFactory(this));
660647
},
648+
findKey: function(predicate, context) {
649+
var foundKey;
650+
this.__iterate((function(v, k, c) {
651+
if (predicate.call(context, v, k, c)) {
652+
foundKey = k;
653+
return false;
654+
}
655+
}));
656+
return foundKey;
657+
},
658+
findLastKey: function(predicate, context) {
659+
return this.toSeq().reverse().findKey(predicate, context);
660+
},
661+
keyOf: function(searchValue) {
662+
return this.findKey((function(value) {
663+
return is(value, searchValue);
664+
}));
665+
},
666+
lastKeyOf: function(searchValue) {
667+
return this.toSeq().reverse().keyOf(searchValue);
668+
},
661669
mapEntries: function(mapper, context) {
662670
var $__0 = this;
663671
var iterations = 0;
@@ -711,16 +719,16 @@ var IndexedIterable = function IndexedIterable(value) {
711719
return reify(this, filterFactory(this, predicate, context, false));
712720
},
713721
findIndex: function(predicate, context) {
714-
var key = this.findKey(predicate, context);
722+
var key = this.toKeyedSeq().findKey(predicate, context);
715723
return key === undefined ? -1 : key;
716724
},
717725
indexOf: function(searchValue) {
718-
return this.findIndex((function(value) {
719-
return is(value, searchValue);
720-
}));
726+
var key = this.toKeyedSeq().keyOf(searchValue);
727+
return key === undefined ? -1 : key;
721728
},
722729
lastIndexOf: function(searchValue) {
723-
return this.toKeyedSeq().reverse().indexOf(searchValue);
730+
var key = this.toKeyedSeq().lastKeyOf(searchValue);
731+
return key === undefined ? -1 : key;
724732
},
725733
reverse: function() {
726734
return reify(this, reverseFactory(this, false));
@@ -736,7 +744,8 @@ var IndexedIterable = function IndexedIterable(value) {
736744
return reify(this, numArgs === 1 ? spliced : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum)));
737745
},
738746
findLastIndex: function(predicate, context) {
739-
return this.toKeyedSeq().reverse().findIndex(predicate, context);
747+
var key = this.toKeyedSeq().findLastKey(predicate, context);
748+
return key === undefined ? -1 : key;
740749
},
741750
first: function() {
742751
return this.get(0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.