0.0.4 • Published 6 years ago

@keepzen/flp v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

FLP

Some symbol definations:

SymbolDefination
f(t)A function, require one argument, which type is t.
f(t1,t2,...,tn)A function, require n arguments.
f'The variant of functon f, have some result but not differtne parames.
f_nA function, require n argument.

FLP~unary(fn) ⇒ function

Change the fn to unary function.

f(anys) => f'.

Kind: inner method of FLP
Returns: function - - a function just require one arg.

ParamTypeDescription
fnfunctionA function require n args.

FLP~identity(v) ⇒ any

any=>any

Kind: inner method of FLP
Returns: any - - the value was passed in.

ParamType
vany

FLP~constant(v) ⇒ function

any=>f(any)

Kind: inner method of FLP
Returns: function - - a function, which always return the passed v.

ParamType
vany

FLP~paritial(fn, ...presentArgs) ⇒ function

Praital a function.

(fn,...args)=>fm

If fn is a function require n arguments and fm = paritial(fn,arg1,arg2,...argx), then fm is a function require (n-x) arguments and fm(1,2,3) have same mean as fn(arg1,arg2,...argx,1,2,3).

Kind: inner method of FLP

ParamTypeDescription
fnfunctionA function require n arguments.
...presentArgsArray(any)Zero or more arugemnt use to paritial fn.

FLP~reverseArg(fn) ⇒ function

Reverse function fn argumentes.

f_n=>f'_n

If f(a,b,c), and g=reverseArg(f), then 'g(1,2,3) === f(3,2,1)'.

Kind: inner method of FLP

ParamType
fnfunction

FLP~paritialRight(fn, ...presentArgs) ⇒ function

If f is a function require 5 arguments. and g = paritialRight(f,a1,a2,a3), then f(b1,b2,a1,a2,a3) same as g(b1,b2).

(fn,a1,a2,..am) => f'{n-m}

Kind: inner method of FLP

ParamType
fnfunction
...presentArgsArray(any)

FLP~curry(fn, arity) ⇒ function

Curry a function.

See Wikipedia About Currying

Kind: inner method of FLP

ParamTypeDescription
fnfunctionA function have more than one argumentes.
aritynumberHow many argumentes the fn required.

FLP~looseCurry(fn, arity) ⇒ function

Loose curry a function.

If a function fn require 3 argument, it be curried c=curry(fn), to get result, we must do like that c(1)(2)(3).

Now lc=looseCurry(fn), get same result, we can do like: 1. lc(1,2,3) 2. lc(1,2)(3) 3. lc(1)(2,3) 4. lc(1)(2)(3)

Kind: inner method of FLP

ParamTypeDescription
fnfunction
aritynumberHow many argument of fn required.

FLP~uncurry(fn) ⇒ function

Change a churryed function to a loose curry function.

Kind: inner method of FLP

ParamType
fnfunction

FLP~combine(...fns) ⇒ function

Combine the input functions to a new function.

Kind: inner method of FLP
Returns: function - - combined function.

ParamType
...fnsArray(function)

FLP~pipe(...fns) ⇒ function

Pipe functions. pipe(f1,f2,f3,...fn) === combine(fn,...f3,f2,f1)

Kind: inner method of FLP
Returns: function - return fn

ParamType
...fnsArray(function)

FLP~pipeable(fn) ⇒ function

Make the function fn pipeable to other functions.

Kind: inner method of FLP
Returns: function - - A function have a properity .pipe(...fns).

ParamType
fnfunction

FLP~trampoline(ret) ⇒ any

Help a function recursion.

Example:

function sumFromOneTo(n){
  function _sum(ret,i){
    if(i == 0){
      return ret;
    }else{
        //Do some operationes on argumemtes,
        //but delay to call function.
      return _sum.bind(null,ret+n,i-1);
    }
  }
  return trampoline(_sum.bind(0,n));
}

Kind: inner method of FLP

ParamTypeDescription
retfunctionA function need no argument and return a value or return another function need no argument.