@klodianimeri/pipejs
Version:
Pipe functions that provide convenient and efficient ways to work with iterators.
18 lines (17 loc) • 547 B
text/typescript
import { Pipe } from "../pipe.js";
import { Yield } from "../util/index.js";
export function defaultIfEmpty(value: any): Pipe {
return () => {
let isempty: boolean = true;
return (result: IteratorResult<any>): IteratorResult<any> | Array<IteratorResult<any>> => {
if (result?.done) {
if (isempty) {
return [Yield(value), result];
}
} else {
isempty = false;
}
return result;
};
}
}