Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
[1.0.12] Expose idx and key in Collection#find predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
auguwu committed Jun 1, 2021
1 parent ebbdac2 commit eeb7f04
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ declare module '@augu/collections' {
* @returns The value found or `null` if not found
*/
find<ThisArg = Collection<K, V>>(
predicate: MinimalPredicate<ThisArg, V, boolean>,
predicate: Predicate<ThisArg, V, number, K, boolean>,
thisArg?: ThisArg
): V | null;

Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@augu/collections",
"description": "📝 Collections library made in TypeScript",
"version": "1.0.11",
"version": "1.0.12",
"types": "index.d.ts",
"main": "build/index.js",
"funding": {
Expand Down
14 changes: 4 additions & 10 deletions src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,13 @@ export class Collection<K, V = unknown> extends Map<K, V> {
* @returns The value found or `null` if not found
*/
find<ThisArg = Collection<K, V>>(
predicate: MinimalPredicate<ThisArg, V, boolean>,
predicate: Predicate<ThisArg, V, number, K, boolean>,
thisArg?: ThisArg
) {
let func: UndetailedMinimalPredicate<V, boolean>;

if (thisArg !== undefined)
func = predicate.bind(thisArg);
else
func = predicate.bind(<any> this);

let idx = -1;
let result: V | null = null;
for (const value of this.values()) {
if (func(value)) {
for (const [key, value] of this.entries()) {
if (predicate.call(thisArg !== undefined ? thisArg : this as any, value, ++idx, key)) {
result = value;
break;
}
Expand Down

0 comments on commit eeb7f04

Please sign in to comment.