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.8 to 1.0.9

lib/retry.js

24

lib/index.js

@@ -137,2 +137,26 @@ "use strict";

});
});
var _retry = require("./retry");
Object.keys(_retry).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _retry[key];
}
});
});
var _settle = require("./settle");
Object.keys(_settle).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _settle[key];
}
});
});

8

lib/pipe.js

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

});
exports.pipe = exports.isAsyncFunction = void 0;
exports.pipe = exports.thennable = void 0;
const isAsyncFunction = v => v && v.then && typeof v.then === 'function' || v && v[Symbol.toStringTag] === 'AsyncFunction';
const thennable = v => v && v.then && typeof v.then === 'function' || v && v[Symbol.toStringTag] === 'AsyncFunction';
exports.isAsyncFunction = isAsyncFunction;
exports.thennable = thennable;
const pipe = (...fn) => initial => fn.reduce((a, n) => isAsyncFunction(n) ? n.then(a) : n(a), initial);
const pipe = (...fn) => initial => fn.reduce((a, n) => thennable(a) ? a.then(n) : n(a), initial);
exports.pipe = pipe;
{
"name": "@teleology/fp",
"version": "1.0.8",
"version": "1.0.9",
"description": "A small collection of functional programming utils",

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

@@ -196,4 +196,47 @@ # @teleology/fp

## retry
Given a function that may throw, retry up to `n` times.
Example:
```javascript
const { retry } = require('@teleology/fp');
const greet = retry(async (name) => {
throw new Error(`${name}, failed to be greeted`);
}, 3);
greet('bob').catch(console.log); // e Error: bob, failed to be greeted
```
## settle
Mimics the traditional `Promise.all` but wraps each promise to avoid a throw. Errors contain a reason, successes a value. If a single promise is passed in, the result is a curried promise whose result is wrapped.
```javascript
const { settle } = require('@teleology/fp');
const ps = [0, 1, 2, 3, 4].map((a) => (async () => a)());
settle(ps).then(console.log);
// [
// { success: true, value: 0 },
// { success: true, value: 1 },
// { success: true, value: 2 },
// { success: true, value: 3 },
// { success: true, value: 4 },
// ]
const safe = settle(async (num) => {
throw new Error(`Failed, ${num}`);
});
safe(10).then(console.log);
// {
// success: false,
// reason: Error: Failed, 10
// ...
// }
```
----

@@ -203,2 +246,6 @@

**1.0.9**
- Adding `retry, settle` functions
- Bug fixes for pipe + compose
**1.0.6**

@@ -205,0 +252,0 @@ - Adding `once` function

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