Skip to content

Commit

Permalink
Replace our arrays.find with stdlib find
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Sep 10, 2020
1 parent d82bb0e commit 310e5a9
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 26 deletions.
15 changes: 0 additions & 15 deletions src/vs/base/common/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,21 +549,6 @@ export function pushToEnd<T>(arr: T[], value: T): void {
}
}


/**
* @deprecated ES6: use `Array.find`
*/
export function find<T>(arr: ArrayLike<T>, predicate: (value: T, index: number, arr: ArrayLike<T>) => any): T | undefined {
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
if (predicate(element, i, arr)) {
return element;
}
}

return undefined;
}

export function mapArrayOrNot<T, U>(items: T | T[], fn: (_: T) => U): U | U[] {
return Array.isArray(items) ?
items.map(fn) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { StandardTokenType } from 'vs/editor/common/modes';
import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair';
import { TokenText, createFakeScopedLineTokens } from 'vs/editor/test/common/modesTestUtils';
import { StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { find } from 'vs/base/common/arrays';

suite('CharacterPairSupport', () => {

Expand Down Expand Up @@ -55,7 +54,7 @@ suite('CharacterPairSupport', () => {
});

function findAutoClosingPair(characterPairSupport: CharacterPairSupport, character: string): StandardAutoClosingPairConditional | undefined {
return find(characterPairSupport.getAutoClosingPairs(), autoClosingPair => autoClosingPair.open === character);
return characterPairSupport.getAutoClosingPairs().find(autoClosingPair => autoClosingPair.open === character);
}

function testShouldAutoClose(characterPairSupport: CharacterPairSupport, line: TokenText[], character: string, column: number): boolean {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/output/common/outputLinkComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as strings from 'vs/base/common/strings';
import { Range } from 'vs/editor/common/core/range';
import { isWindows } from 'vs/base/common/platform';
import { Schemas } from 'vs/base/common/network';
import { find } from 'vs/base/common/arrays';

export interface ICreateData {
workspaceFolders: string[];
Expand Down Expand Up @@ -47,7 +46,7 @@ export class OutputLinkComputer {
private getModel(uri: string): IMirrorModel | undefined {
const models = this.ctx.getMirrorModels();

return find(models, model => model.uri.toString() === uri);
return models.find(model => model.uri.toString() === uri);
}

computeLinks(uri: string): ILink[] {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { escapeNonWindowsPath } from 'vs/workbench/contrib/terminal/common/terminalEnvironment';
import { isWindows, isMacintosh, OperatingSystem, isWeb } from 'vs/base/common/platform';
import { basename } from 'vs/base/common/path';
import { find } from 'vs/base/common/arrays';
import { timeout } from 'vs/base/common/async';
import { IViewsService, ViewContainerLocation, IViewDescriptorService } from 'vs/workbench/common/views';
import { IDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -459,7 +458,7 @@ export class TerminalService implements ITerminalService {
}

private _getTabForInstance(instance: ITerminalInstance): ITerminalTab | undefined {
return find(this._terminalTabs, tab => tab.terminalInstances.indexOf(instance) !== -1);
return this._terminalTabs.find(tab => tab.terminalInstances.indexOf(instance) !== -1);
}

public async showPanel(focus?: boolean): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class WelcomePageContribution implements IWorkbenchContribution {
.then(folder => {
const files = folder.children ? folder.children.map(child => child.name) : [];

const file = arrays.find(files.sort(), file => strings.startsWith(file.toLowerCase(), 'readme'));
const file = files.sort().find(file => strings.startsWith(file.toLowerCase(), 'readme'));
if (file) {
return joinPath(folderUri, file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { ICredentialsProvider, ICredentialsService } from 'vs/platform/credentials/common/credentials';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { find } from 'vs/base/common/arrays';

export class BrowserCredentialsService implements ICredentialsService {

Expand Down Expand Up @@ -80,7 +79,7 @@ class InMemoryCredentialsProvider implements ICredentialsProvider {
}

private doFindPassword(service: string, account?: string): ICredential | undefined {
return find(this.credentials, credential =>
return this.credentials.find(credential =>
credential.service === service && (typeof account !== 'string' || credential.account === account));
}

Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import { Schemas } from 'vs/base/common/network';
import { IProductService } from 'vs/platform/product/common/productService';
import product from 'vs/platform/product/common/product';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { find } from 'vs/base/common/arrays';
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IFilesConfigurationService, FilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
Expand Down Expand Up @@ -556,7 +555,7 @@ export class TestEditorGroupsService implements IEditorGroupsService {
get count(): number { return this.groups.length; }

getGroups(_order?: GroupsOrder): ReadonlyArray<IEditorGroup> { return this.groups; }
getGroup(identifier: number): IEditorGroup | undefined { return find(this.groups, group => group.id === identifier); }
getGroup(identifier: number): IEditorGroup | undefined { return this.groups.find(group => group.id === identifier); }
getLabel(_identifier: number): string { return 'Group 1'; }
findGroup(_scope: IFindGroupScope, _source?: number | IEditorGroup, _wrap?: boolean): IEditorGroup { throw new Error('not implemented'); }
activateGroup(_group: number | IEditorGroup): IEditorGroup { throw new Error('not implemented'); }
Expand Down

0 comments on commit 310e5a9

Please sign in to comment.