Fix imapfilter typing
This commit is contained in:
parent
43d5678697
commit
8fbb5c4ad1
11
mod.ts
11
mod.ts
|
@ -341,17 +341,16 @@ export function ifilter<T>(
|
||||||
/**
|
/**
|
||||||
* Apply map, and filter invalid results in the same pass.
|
* Apply map, and filter invalid results in the same pass.
|
||||||
*/
|
*/
|
||||||
export function imapfilter<T1, T2, E>(
|
export function imapfilter<T1, T2>(
|
||||||
iterable: Iterable<T1>,
|
iterable: Iterable<T1>,
|
||||||
mapfunc: (_: T1) => Exclude<T2, E> | typeof exclusion,
|
mapfunc: (_: T1) => T2 | null,
|
||||||
exclusion: E = null as unknown as E,
|
): Iterable<Exclude<T2, null>> {
|
||||||
): Iterable<T2> {
|
|
||||||
return {
|
return {
|
||||||
[Symbol.iterator]: function* () {
|
[Symbol.iterator]: function* () {
|
||||||
for (let value of iterable) {
|
for (let value of iterable) {
|
||||||
const mapped = mapfunc(value);
|
const mapped = mapfunc(value);
|
||||||
if (mapped !== exclusion) {
|
if (mapped !== null) {
|
||||||
yield mapped as T2;
|
yield mapped as Exclude<T2, null>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue