Skip to content

Commit 7d5db88

Browse files
committed
fix(remove): replace remove(remover) with removeBy(remover)
1 parent 34be529 commit 7d5db88

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/collection.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Any, createFunctionSpy, Expect, Test, TestCase, TestFixture } from 'alsatian';
22
import { Customiser, Filter } from './';
3-
import { Collection, Dictionary, Finder, Replacer } from './collection';
3+
import { Collection, Dictionary, Finder, Remover, Replacer } from './collection';
44

55
function createTestingCollection<T>(definition: Dictionary<T>, firstIndex?: number, lastIndex?: number) {
66
const collection = new Collection();
@@ -76,11 +76,11 @@ export class CollectionTests {
7676
createTestingCollection({ '1': 'b', '2': 'c', '3': 'd', '4': 'e' }),
7777
(item: string) => item === 'a'
7878
)
79-
@Test('remove(filter: Filter<TItem>) should remove items that the filter returns true to from a collection')
80-
public remove2<T>(items: T[], expected: Collection<T>, filter: Filter<T>) {
79+
@Test('removeBy(remover: Remover<TItem>) should remove items that the filter returns true to from a collection')
80+
public removeBy1<T>(items: T[], expected: Collection<T>, remover: Remover<T>) {
8181
const collection = new Collection<T>(items);
8282

83-
collection.remove(filter);
83+
collection.removeBy(remover);
8484

8585
Expect(collection).toEqual(expected);
8686
}

src/collection.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,22 @@ export class Collection<TItem> {
103103
return this;
104104
}
105105

106-
public remove(item: TItem): Collection<TItem>;
107-
public remove(remover: Remover<TItem>): Collection<TItem>;
108-
public remove(itemOrRemover: TItem | Remover<TItem>): Collection<TItem> {
109-
if (typeof itemOrRemover === 'function') {
110-
this.enumerate((item, index, collection) => {
111-
if ((<Remover<TItem>>itemOrRemover)(item, index, collection)) {
112-
this.delete(index);
113-
}
114-
});
115-
} else {
116-
const index = this.findIndex(itemOrRemover);
106+
public remove(item: TItem): Collection<TItem> {
107+
const index = this.findIndex(item);
117108

118-
if (index !== undefined) {
109+
if (index !== undefined) {
110+
this.delete(index);
111+
}
112+
113+
return this;
114+
}
115+
116+
public removeBy(remover: Remover<TItem>): Collection<TItem> {
117+
this.enumerate((item, index, collection) => {
118+
if (remover(item, index, collection)) {
119119
this.delete(index);
120120
}
121-
}
121+
});
122122

123123
return this;
124124
}
@@ -181,7 +181,7 @@ export class Collection<TItem> {
181181
}
182182

183183
public clear(): Collection<TItem> {
184-
this.remove(() => true);
184+
this.removeBy(() => true);
185185

186186
return this;
187187
}

0 commit comments

Comments
 (0)