Methods
(static) concatFn() → {function}
concat functions
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
...fns |
function |
<repeatable> |
variable length parameters |
- Source:
Returns:
return a new function formed by the combination of multiple functions
- Type
- function
Example
function a () {
console.log(1)
}
function b () {
console.log(2)
}
var fn = concatFn(a, b)
fn() // => 1, 2
(static) curry(fn) → {function}
function currying
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function | the function to be fixed paramters | |
...args |
* |
<repeatable> |
variable length parameters |
- Source:
Returns:
return a new function with fixed parameters
- Type
- function
Example
function add (a, b) {
return a + b
}
var fn = curry(1)
fn(2) // => 3
(static) indefiniteArgs(conf) → {function}
generating a function to assign indefinite arguments
Parameters:
Name | Type | Description |
---|---|---|
conf |
object |
- Source:
Returns:
- Type
- function
Example
const fn = indefiniteArgs({
base: [0, 1] // default arguments
args: [
// if recieves zero parameter
// the undefined is the same as `args => args`
undefined,
// if recieves one parameter
// args is an array copy from arguments,
// the result of this function is the result of defAssign(base, [undefined].concat(args))
args => [undefined].concat(args),
// if recieves two parameter,
// the result of this function is the result of defAssign(base, [0, 1])
[0, 1]
]
})
let [arg0, arg1] = fn() // arg0: 0, arg1: 1
let [arg0, arg1] = fn(1) // arg0: 0, arg1: 1
let [arg0, arg1, arg2] = fn(0, 0, 0) // arg0: 0, arg1: 1, arg2: undefined
let [arg0, arg1, arg2, arg3] = fn(1, 2, 3, 4) // arg0: 0, arg1: 1, arg2: 2, arg3: 3, arg4: 4
// is equal to:
const { defAssign } = require('dark-fns').array
function fn () {
let base = [0, 1]
if (len === 1) {
return defAssign(base, [undefined].concat(args))
} else if (len === 2) {
return defAssign(base, [0, 1])
}
// the `args.undefined` of conf
else {
return defAssign(base, [0, 1])
}
}