@keepzen/flp v0.0.4
FLP
Some symbol definations:
| Symbol | Defination |
|---|---|
| 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_n | A function, require n argument. |
- FLP
- ~unary(fn) ⇒ function
- ~identity(v) ⇒ any
- ~constant(v) ⇒ function
- ~paritial(fn, ...presentArgs) ⇒ function
- ~reverseArg(fn) ⇒ function
- ~paritialRight(fn, ...presentArgs) ⇒ function
- ~curry(fn, arity) ⇒ function
- ~looseCurry(fn, arity) ⇒ function
- ~uncurry(fn) ⇒ function
- ~combine(...fns) ⇒ function
- ~pipe(...fns) ⇒ function
- ~pipeable(fn) ⇒ function
- ~trampoline(ret) ⇒ any
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.
| Param | Type | Description |
|---|---|---|
| fn | function | A function require n args. |
FLP~identity(v) ⇒ any
any=>any
Kind: inner method of FLP
Returns: any - - the value was passed in.
| Param | Type |
|---|---|
| v | any |
FLP~constant(v) ⇒ function
any=>f(any)
Kind: inner method of FLP
Returns: function - - a function,
which always return the passed v.
| Param | Type |
|---|---|
| v | any |
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
| Param | Type | Description |
|---|---|---|
| fn | function | A function require n arguments. |
| ...presentArgs | Array(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
| Param | Type |
|---|---|
| fn | function |
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
| Param | Type |
|---|---|
| fn | function |
| ...presentArgs | Array(any) |
FLP~curry(fn, arity) ⇒ function
Curry a function.
Kind: inner method of FLP
| Param | Type | Description |
|---|---|---|
| fn | function | A function have more than one argumentes. |
| arity | number | How 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
| Param | Type | Description |
|---|---|---|
| fn | function | |
| arity | number | How many argument of fn required. |
FLP~uncurry(fn) ⇒ function
Change a churryed function to a loose curry function.
Kind: inner method of FLP
| Param | Type |
|---|---|
| fn | function |
FLP~combine(...fns) ⇒ function
Combine the input functions to a new function.
Kind: inner method of FLP
Returns: function - - combined function.
| Param | Type |
|---|---|
| ...fns | Array(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
| Param | Type |
|---|---|
| ...fns | Array(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).
| Param | Type |
|---|---|
| fn | function |
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
| Param | Type | Description |
|---|---|---|
| ret | function | A function need no argument and return a value or return another function need no argument. |