Add firstOrDefault helper

Array accesses are not strict null checked. Added a type checked helper for when you just want to get the first element of an array of fallback to a default if the array is empty
This commit is contained in:
Matt Bierner
2019-09-17 16:38:27 -07:00
parent 766352d992
commit 36b66c90e9
5 changed files with 15 additions and 30 deletions

View File

@@ -1665,11 +1665,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
getWindowById(windowId: number): ICodeWindow | undefined {
const res = WindowsManager.WINDOWS.filter(window => window.id === windowId);
if (res && res.length === 1) {
return res[0];
}
return undefined;
return arrays.firstOrDefault(res);
}
getWindows(): ICodeWindow[] {