Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@teleology/fp

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teleology/fp - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/filter.js

5

lib/broadcast.js

@@ -8,4 +8,9 @@ "use strict";

/**
* Invokes all curried functions in paralell.
*
* @param {any|Array} args Any number of arguments
*/
const broadcast = (...fns) => (...args) => Promise.all(fns.map(fn => fn(...args)));
exports.broadcast = broadcast;

30

lib/index.js

@@ -7,5 +7,5 @@ "use strict";

var _broadcast = require("./broadcast");
var _parallel = require("./parallel");
Object.keys(_broadcast).forEach(function (key) {
Object.keys(_parallel).forEach(function (key) {
if (key === "default" || key === "__esModule") return;

@@ -15,3 +15,3 @@ Object.defineProperty(exports, key, {

get: function () {
return _broadcast[key];
return _parallel[key];
}

@@ -57,2 +57,26 @@ });

var _filter = require("./filter");
Object.keys(_filter).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _filter[key];
}
});
});
var _find = require("./find");
Object.keys(_find).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _find[key];
}
});
});
var _pick = require("./pick");

@@ -59,0 +83,0 @@

8

lib/toss.js

@@ -8,6 +8,10 @@ "use strict";

const toss = msg => {
throw new Error(msg || 'An unknown error occured');
const toss = msg => (properties = {}) => {
const e = new Error(msg || 'An unknown error occured');
Object.assign(e, {
properties
});
throw e;
};
exports.toss = toss;
{
"name": "@teleology/fp",
"version": "1.0.0",
"version": "1.0.1",
"description": "A small collection of functional programming utils",

@@ -5,0 +5,0 @@ "repository": "git@github.com:icarus-sullivan/teleology-fp.git",

# @teleology/fp
A collection of functional utilities supporting pipes
## pipe
Accepts a variadic list of functions and passes one argument to the next from top-to-bottom.
Example:
```javascript
const { pipe } = require('@teleology/fp');
const a = (s) => s - 12;
const b = (s) => s * 3;
pipe(
a,
b,
console.log
)(10); // -6
```
## compose
Accepts a variadic list of functions and passes one argument to the next from bottom-to-top.
Example:
```javascript
const { compose } = require('@teleology/fp');
const a = (s) => s - 12;
const b = (s) => s * 3;
compose(
console.log,
a,
b
)(10); // 18
```
## parallel
Accepts a variadic list of functions and returns a curried function. The curried function can then be invoked and will delegate its arguments in parallel across the functions.
Example:
```javascript
const { parallel } = require('@teleology/fp');
const logDb = require('./apis/logs');
// Writes to both local logs as well as to our external api
const logger = parallel(
logDb,
console.log
);
logger({
source: 'app',
action: 'clicked login',
time: Date.now(),
});
```
## toss
Curries an error message returning an invocable function to throw. The invocable function can accept params
to assign additional data to the Error.
Example:
```javascript
const { toss } = require('@teleology/fp');
toss('An error occured')({ code: 103, reason: 'Entity already exists' });
// Error: An error occured
// ...
// at internal/main/run_main_module.js:17:47 {
// properties: { code: 103, reason: 'Entity already exists' }
// }
```
## pick
Curry a dot notation path and default value, returns an invocable function requiring a target object.
Example:
```javascript
const { toss } = require('@teleology/fp');
pick('[0].a.b')([
{
a: {
b: 'hello',
},
},
]); // hello
```
## map
A curried map function to be invoked within an Array.
Example:
```javascript
const { map } = require('@teleology/fp');
map((a) => a.id)([
{
id: '1',
},
{
id: '2',
},
]); // [ '1', '2' ]
```
## filter
A curried filter function to be invoked within an Array.
Example:
```javascript
const { filter } = require('@teleology/fp');
filter((a) => a.id === '1')([
{
id: '1',
},
{
id: '2',
},
]); // [ '1' ]
```
## find
A curried find function to be invoked within an Array.
Example:
```javascript
const { find } = require('@teleology/fp');
find((a) => a.id === '1')([
{
id: '1',
},
{
id: '2',
},
]); // { id: '1' }
```
----
## Changelog
**1.0.1**
- Renaming broadcast to parallel
- Added find, filter functions
- Updated README with examples
- Updated `toss` to be invoked later to capture param
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc