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