UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Lazy = void 0;
4/**
5 * @description this class is not strict type, be ware of the type <A>
6 * */
7class Lazy {
8 constructor(f) {
9 this.f = f;
10 }
11 value() {
12 const res = this.f();
13 delete this.f;
14 this.value = () => res;
15 return res;
16 }
17 map(f) {
18 return new Lazy(() => f(this.value()));
19 }
20 add(b) {
21 return this.map(a => a + b);
22 }
23 minus(b) {
24 return this.map(a => a - b);
25 }
26 mult(b) {
27 return this.map(a => a * b);
28 }
29 rem(b) {
30 return this.map(a => a % b);
31 }
32 div(b) {
33 return this.map(a => a / b);
34 }
35 quot(b) {
36 /* tslint:disable no-bitwise */
37 return this.map(a => (a / b) | 0);
38 /* tslint:enable no-bitwise */
39 }
40 quotRem(b) {
41 return this.map((a) => {
42 /* tslint:disable no-bitwise */
43 return [(a / b) | 0, a % b];
44 /* tslint:enable no-bitwise */
45 });
46 }
47 and(b) {
48 return this.map(a => a && b);
49 }
50 or(b) {
51 return this.map(a => a || b);
52 }
53 not() {
54 return this.map(a => !a);
55 }
56 notnot() {
57 return this.map(a => !!a);
58 }
59}
60exports.Lazy = Lazy;
61//# sourceMappingURL=lazy.js.map
\No newline at end of file