@teleology/fp
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -8,4 +8,16 @@ "use strict"; | ||
const filter = fn => src => Array.isArray(src) ? src.filter(fn) : []; | ||
const { | ||
objecToEquality | ||
} = require('./arrays'); | ||
const filter = arg => src => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = objecToEquality(arg); | ||
} | ||
return Array.isArray(src) ? src.filter(fn) : []; | ||
}; | ||
exports.filter = filter; |
@@ -8,4 +8,16 @@ "use strict"; | ||
const find = fn => src => Array.isArray(src) ? src.find(fn) : undefined; | ||
const { | ||
objecToEquality | ||
} = require('./arrays'); | ||
const find = arg => src => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = objecToEquality(arg); | ||
} | ||
return Array.isArray(src) ? src.find(fn) : undefined; | ||
}; | ||
exports.find = find; |
@@ -8,4 +8,16 @@ "use strict"; | ||
const map = fn => src => Array.isArray(src) ? src.map(fn) : src ? fn(src, 0, src) : undefined; | ||
const { | ||
pick | ||
} = require('./pick'); | ||
const map = arg => src => { | ||
let fn = arg; | ||
if (Array.isArray(arg)) { | ||
fn = pick(arg); | ||
} | ||
return Array.isArray(src) ? src.map(fn) : src ? fn(src, 0, src) : undefined; | ||
}; | ||
exports.map = map; |
{ | ||
"name": "@teleology/fp", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A small collection of functional programming utils", | ||
@@ -5,0 +5,0 @@ "author": "Chris Sullivan <chrissullivan.dev@gmail.com>", |
@@ -128,3 +128,21 @@ # @teleology/fp | ||
## curry | ||
Curry a specific function with a known [arity](https://en.wikipedia.org/wiki/Arity). Please note, optional arguments are not considered during invocation unless they are explicity set. | ||
Example: | ||
```javascript | ||
const { curry } = require('@teleology/fp'); | ||
const test = (a, b, c) => console.log([a, b, c]); | ||
const curried = curry(3, test); | ||
// allows for flexibility | ||
curried(1, 2, 3); // [1, 2, 3] | ||
curried(1)(2)(3); // [1, 2, 3] | ||
curried(1)(2, 3); // [1, 2, 3] | ||
curried(1, 2)(3); // [1, 2, 3] | ||
``` | ||
## map | ||
@@ -146,21 +164,13 @@ | ||
]); // [ '1', '2' ] | ||
``` | ||
## curry | ||
Curry a specific function with a known [arity](https://en.wikipedia.org/wiki/Arity). Please note, optional arguments are not considered during invocation unless they are explicity set. | ||
Example: | ||
```javascript | ||
const { curry } = require('@teleology/fp'); | ||
const test = (a, b, c) => console.log([a, b, c]); | ||
const curried = curry(3, test); | ||
// allows for flexibility | ||
curried(1, 2, 3); // [1, 2, 3] | ||
curried(1)(2)(3); // [1, 2, 3] | ||
curried(1)(2, 3); // [1, 2, 3] | ||
curried(1, 2)(3); // [1, 2, 3] | ||
map(['id'])([ | ||
{ | ||
id: '1', | ||
name: 'bob', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'chris', | ||
}, | ||
]) // [ { id: '1' }, { id: '2' } ] | ||
``` | ||
@@ -184,2 +194,11 @@ | ||
]); // [ { id: '1' } ] | ||
filter({ id: '1' })([ | ||
{ | ||
id: '1', | ||
}, | ||
{ | ||
id: '2', | ||
}, | ||
]); // [ { id: '1' } ] | ||
``` | ||
@@ -204,5 +223,41 @@ | ||
]); // { id: '1' } | ||
find({ id: '1' })([ | ||
{ | ||
id: '1', | ||
}, | ||
{ | ||
id: '2', | ||
}, | ||
]); // { id: '1' } | ||
``` | ||
## some | ||
A curried some function to be invoked within an Array. | ||
Example: | ||
```javascript | ||
const { some } = require('@teleology/fp'); | ||
some((a) => a.id === '1')([ | ||
{ | ||
id: '1', | ||
}, | ||
{ | ||
id: '2', | ||
}, | ||
]); // true | ||
some({ id: '1' })([ | ||
{ | ||
id: '1', | ||
}, | ||
{ | ||
id: '2', | ||
}, | ||
]); // true | ||
``` | ||
## clean | ||
@@ -209,0 +264,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22882
23
471
413