@beenotung/tslib
Version:
utils library in Typescript
61 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lazy = void 0;
/**
* @description this class is not strict type, be ware of the type <A>
* */
class Lazy {
constructor(f) {
this.f = f;
}
value() {
const res = this.f();
delete this.f;
this.value = () => res;
return res;
}
map(f) {
return new Lazy(() => f(this.value()));
}
add(b) {
return this.map(a => a + b);
}
minus(b) {
return this.map(a => a - b);
}
mult(b) {
return this.map(a => a * b);
}
rem(b) {
return this.map(a => a % b);
}
div(b) {
return this.map(a => a / b);
}
quot(b) {
/* tslint:disable no-bitwise */
return this.map(a => (a / b) | 0);
/* tslint:enable no-bitwise */
}
quotRem(b) {
return this.map((a) => {
/* tslint:disable no-bitwise */
return [(a / b) | 0, a % b];
/* tslint:enable no-bitwise */
});
}
and(b) {
return this.map(a => a && b);
}
or(b) {
return this.map(a => a || b);
}
not() {
return this.map(a => !a);
}
notnot() {
return this.map(a => !!a);
}
}
exports.Lazy = Lazy;
//# sourceMappingURL=lazy.js.map