mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Add code examples to fp wiki. [ci skip]
This commit is contained in:
@@ -31,6 +31,17 @@ to convert each method.
|
|||||||
|
|
||||||
#### Capped Iteratee Arguments
|
#### Capped Iteratee Arguments
|
||||||
|
|
||||||
|
Iteratee arguments are capped to avoid gotchas with variadic iteratees.
|
||||||
|
```js
|
||||||
|
// The `lodash/map` iteratee recieves three arguments: (value, index|key, collection).
|
||||||
|
_.map(['6', '8', '10'], parseInt);
|
||||||
|
// → [6, NaN, 2]
|
||||||
|
|
||||||
|
// The `lodash/fp/map` iteratee is capped at one argument: (value).
|
||||||
|
fp.map(parseInt)(['6', '8', '10']);
|
||||||
|
// → [6, 8, 10]
|
||||||
|
```
|
||||||
|
|
||||||
Methods that cap iteratees to one argument:<br>
|
Methods that cap iteratees to one argument:<br>
|
||||||
<%= toFuncList(_.keys(_.pickBy(mapping.iterateeAry, _.partial(_.eq, _, 1)))) %>
|
<%= toFuncList(_.keys(_.pickBy(mapping.iterateeAry, _.partial(_.eq, _, 1)))) %>
|
||||||
|
|
||||||
@@ -41,6 +52,19 @@ The iteratee of `mapKeys` is invoked with one argument: (key)
|
|||||||
|
|
||||||
#### Fixed Arity
|
#### Fixed Arity
|
||||||
|
|
||||||
|
Methods have fixed arities to support auto-currying.
|
||||||
|
```js
|
||||||
|
// The `lodash/padStart` method accepts an optional `chars` param.
|
||||||
|
_.padStart('a', 3, '-')
|
||||||
|
// → '--a'
|
||||||
|
|
||||||
|
// The `lodash/fp/padStart` method does not.
|
||||||
|
fp.padStart(3)('a');
|
||||||
|
// → ' a'
|
||||||
|
fp.padCharsStart('-')(3)('a');
|
||||||
|
// → '--a'
|
||||||
|
```
|
||||||
|
|
||||||
Methods with a fixed arity of one:<br>
|
Methods with a fixed arity of one:<br>
|
||||||
<%= toFuncList(mapping.aryMethod[1]) %>
|
<%= toFuncList(mapping.aryMethod[1]) %>
|
||||||
|
|
||||||
@@ -55,6 +79,19 @@ Methods with a fixed arity of four:<br>
|
|||||||
|
|
||||||
#### Rearranged Arguments
|
#### Rearranged Arguments
|
||||||
|
|
||||||
|
Method arguments are rearranged to make composition easier.
|
||||||
|
```js
|
||||||
|
// The `lodash/filter` method accepts (collection, iteratee).
|
||||||
|
var compact = _.partial(_.filter, _, Boolean);
|
||||||
|
compact(['a', null, 'c']);
|
||||||
|
// → ['a', 'c']
|
||||||
|
|
||||||
|
// The `lodash/fp/filter` method accepts (iteratee, collection)
|
||||||
|
var compact = fp.filter(Boolean);
|
||||||
|
compact(['a', null, 'c']);
|
||||||
|
// → ['a', 'c']
|
||||||
|
```
|
||||||
|
|
||||||
Methods with a fixed arity of two have an argument order of:<br>
|
Methods with a fixed arity of two have an argument order of:<br>
|
||||||
<%= toArgOrder(mapping.aryRearg[2]) %>
|
<%= toArgOrder(mapping.aryRearg[2]) %>
|
||||||
|
|
||||||
@@ -77,6 +114,10 @@ apply as their second parameter.
|
|||||||
|
|
||||||
#### New Methods
|
#### New Methods
|
||||||
|
|
||||||
|
Not all variadic methods have corresponding new method variants. Feel free to
|
||||||
|
[request](https://github.com/lodash/lodash/blob/master/.github/CONTRIBUTING.md#feature-requests)
|
||||||
|
any additions.
|
||||||
|
|
||||||
Methods created to accommodate Lodash’s variadic methods:<br>
|
Methods created to accommodate Lodash’s variadic methods:<br>
|
||||||
<%= toFuncList(_.keys(mapping.remap)) %>
|
<%= toFuncList(_.keys(mapping.remap)) %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user