Home Reference Source Repository

Function

Static Public Summary
public

cast(arr: any, n: number): Array<any> | T[] | Error

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

equality(x: any, y: any): boolean

It checks equality of given arguments, arguments must be statically analyzable, therefore there are some constraints, look at examples to find them.

public

hash(str: string, pHash: number): number

Calculates a hash (32 bit).

public

wait(v: any, t: number): Promise<T>

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:

NameTypeAttributeDescription
arr any

input array.

n number

decreasing factor.

Return:

Array<any> | T[] | Error

public clone(obj: T): T source

import {clone} from 'monad-ts/src/services/clone.js'

The service to clone complex objects, including Map.

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
f function

invoked function.

d number

a delay time.

immediate boolean
  • optional
  • default: true

immediate - first func call is immediate if true.

Return:

function(...args: any[])

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:

NameTypeAttributeDescription
x any

argument 1, can include null, NaN etc.

y any

argument 2, can include null, NaN etc.

Return:

boolean

Example:

1)
 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}};}
     )
2)
 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
3)
 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/

Params:

NameTypeAttributeDescription
str string

string to hash

pHash number
  • optional
  • default: 2166136261

previous hash.

Return:

number

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:

NameTypeAttributeDescription
v any

value should be returned.

t number
  • optional
  • default: 0

t - amount of time, in millis.

Return:

Promise<T>