Function
Static Public Summary | ||
public |
Decreasing the dimension of an array by n. |
|
public |
clone(obj: T): T The service to clone complex objects, including Map. |
|
public |
debounceTime(f: function, d: number, immediate: boolean): function(...args: any[]) Execute a function given a delay time. |
|
public |
It checks equality of given arguments, arguments must be statically analyzable, therefore there are some constraints, look at examples to find them. |
|
public |
Calculates a hash (32 bit). |
|
public |
Converts timeout in a Promise, resolved when specified amount of time passes. |
Static Public
public cast(arr: any, n: number): Array<any> | T[] | Error source
import {cast} from 'monad-ts/src/services/cast.js'
Decreasing the dimension of an array by n.
Params:
Name | Type | Attribute | Description |
arr | any | input array. |
|
n | number | decreasing factor. |
public clone(obj: T): T source
import {clone} from 'monad-ts/src/services/clone.js'
The service to clone complex objects, including Map.
Params:
Name | Type | Attribute | Description |
obj | T | Object or Primitives to clone. |
Return:
T |
public debounceTime(f: function, d: number, immediate: boolean): function(...args: any[]) source
import {debounceTime} from 'monad-ts/src/services/debounceTime.js'
Execute a function given a delay time.
public equality(x: any, y: any): boolean source
import {equality} from 'monad-ts/src/services/equality.js'
It checks equality of given arguments, arguments must be statically analyzable, therefore there are some constraints, look at examples to find them.
Params:
Name | Type | Attribute | Description |
x | any | argument 1, can include null, NaN etc. |
|
y | any | argument 2, can include null, NaN etc. |
Example:
Functions compare by the structure, not by values of variables or other elements it consists of.
Equal:
let d = 20;
equality(
()=>{return ()=> {return {'g': d}};},
function(){return function() {return{'g': d}};}
)
Not Equal:
let d = 20;
let d2 = 20;
equality(
()=>{return ()=> {return {'g': d}};},
function(){return function() {return{'g': d2}};}
)
Do not use the creation of some objects by object creation, they will be compared wrong.
Never use this constructions in compared objects:
new Boolean(*);
new Number(*);
Error(*);
new Error(*);
new Date(*);
new RegExp(*);
Equal:
equality(new Boolean(true), new Boolean(false)); // Wrong
equality(Error('true'), Error('false')); // Wrong
equality(new Number(1), new Number(11)); // Wrong
equality(new Date(1995, 11, 17), new Date('1995-12-17T03:24:00')) // Wrong
Not Equal (the exception of `new` option in some cases can solve the issue):
equality(Boolean(true), Boolean(false)); // Right
equality(Number(1), Number(11)); // Right
Instances of a user-defined object type that has a constructor function are compared as objects by `key: value`.
class Test{
constructor(private arg: any){ }
}
class Test2{
constructor(private arg: any){ }
}
Equal:
new Test(true) and new Test(true);
Not Equal:
new Test(true) and new Test2(true);
new Test(true) and new Test(false);
public hash(str: string, pHash: number): number source
import {hash} from 'monad-ts/src/services/hash.js'
Calculates a hash (32 bit). Based on FNV-1a algorithm, ref: http://isthe.com/chongo/tech/comp/fnv/
public wait(v: any, t: number): Promise<T> source
import {wait} from 'monad-ts/src/services/wait.js'
Converts timeout in a Promise, resolved when specified amount of time passes.
Params:
Name | Type | Attribute | Description |
v | any | value should be returned. |
|
t | number |
|
t - amount of time, in millis. |