Update and add tests for fp convert method.

This commit is contained in:
John-David Dalton
2016-03-04 00:55:59 -08:00
parent f6df126c43
commit 4debf155d7
4 changed files with 91 additions and 57 deletions

View File

@@ -14,7 +14,7 @@ In a browser:
In Node.js:
```js
// Load the fp build.
var _ = require('lodash/fp');
var fp = require('lodash/fp');
// Load a method category.
var object = require('lodash/fp/object');
@@ -25,27 +25,34 @@ var extend = require('lodash/fp/extend');
## Convert
Although `lodash/fp` & its method modules come pre-converted, there are times when
you may want to customize the conversion. Thats when the `convert` method comes in handy.
Although `lodash/fp` & its method modules come pre-converted, there are times
when you may want to customize the conversion. Thats when the `convert` method
comes in handy.
```js
// Disable capping of the iteratee arguments so it is possible to access
// the `key` argument
var mapValuesWithKey = require("lodash/fp/mapValues").convert({cap: false});
// Every option is `true` by default.
var mapValues = fp.mapValues.convert({
// Specify capping iteratee arguments.
'cap': true,
// Specify currying.
'curry': true,
// Specify fixed arity.
'fixed': true,
// Specify immutable operations.
'immutable': true,
// Specify rearranging arguments.
'rearg': true
});
// Disable capping of iteratee arguments to access the `key` param.
var mapValuesWithKey = fp.mapValues.convert({ 'cap': false });
mapValuesWithKey(function(value, key) {
if (key === "foo") {
return -1;
}
return value;
}, {foo: 1, bar: 1});
// => {foo: -1, bar: 1}
return key == 'a' ? -1 : value;
})({ 'a': 1, 'b': 1 });
// => { 'a': -1, 'b': 1 }
```
It's also possible to use the convert function directly to convert functions or
objects manually.
Its also possible to use the convert module directly for manual conversions.
```js
var convert = require('lodash/fp/convert');
@@ -62,31 +69,6 @@ var fp = convert({
var fp = convert(lodash.runInContext());
```
Its customizable too.
```js
// Every option is `true` by default.
var filter = convert('filter', _.filter, {
// Specify capping iteratee arguments.
'cap': true,
// Specify currying.
'curry': true,
// Specify fixed arity.
'fixed': true,
// Specify immutable operations.
'immutable': true,
// Specify rearranging arguments.
'rearg': true
});
// Specify `cap` of `false` to create a function that doesnt cap iteratee arguments.
var filter = convert('filter', _.filter, { 'cap': false });
filter(function(value, index) {
return index % 2 == 0;
})(['a', 'b', 'c']);
// => ['a', 'c']
```
## Mapping
Immutable auto-curried iteratee-first data-last methods sound great, but what

View File

@@ -1,5 +1,6 @@
module.exports = {
'ary': require('../ary'),
'assign': require('../_baseAssign'),
'clone': require('../clone'),
'curry': require('../curry'),
'forEach': require('../_arrayEach'),