mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -05:00
29 lines
925 B
TypeScript
29 lines
925 B
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
'use strict';
|
|
|
|
export namespace Iterables {
|
|
export function* filterMap<T, TMapped>(
|
|
source: Iterable<T> | IterableIterator<T>,
|
|
predicateMapper: (item: T) => TMapped | undefined | null,
|
|
): Iterable<TMapped> {
|
|
for (const item of source) {
|
|
const mapped = predicateMapper(item);
|
|
// eslint-disable-next-line eqeqeq
|
|
if (mapped != null) { yield mapped; }
|
|
}
|
|
}
|
|
|
|
export function* map<T, TMapped>(
|
|
source: Iterable<T> | IterableIterator<T>,
|
|
mapper: (item: T) => TMapped,
|
|
): Iterable<TMapped> {
|
|
for (const item of source) {
|
|
yield mapper(item);
|
|
}
|
|
}
|
|
}
|