Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
dethunking-compose
Advanced tools
[Function composition](https://en.wikipedia.org/wiki/Function composition) allows the writing of declarative functional code. I like to pair this style of coding with the main functions at the top of a file followed by the definitions of the smaller functions out of which it's composed.
Unfortunately, if you are writing in javascript and using function expressions rather than function statements (because, for example, you are writing curried functions) these can be difficult to combine.
Because the arguments to a javascript function are eagerly evaluated, the functions you are composing have to be defined above the point that you compose them.
This module allows you to pass a series of thunks to a compose function (thus delaying their evaluation) which you allows you to define the smaller functions later (it still has to be before their actual use).
This module also stringifies in a debuggable way.
I'm not sure this module is worth using without the low affordance for writing thunks provided by ES6 arrow functions.
var compose = require('dethunk-compose')
var triple_add_3 = module.exports = compose(
() => add_2,
() => add_1,
() => triple
)
var add_2 = compose(
() => add_1,
() => add_1
)
var add_1 = x => x + 1
var triple = x => x * 3
Compare to this attempt with a normal compose module, which would throw.
var compose = require(/* Normal compose module */)
var add_2 = compose(
add_1,
add_1
)
var add_1 = x => x + 1
add_2(4)
// undefined is not a function
If you prefer to compose left-to-right, you can use the pipe API.
var pipe = require('dethunk-compose).pipe
var triple_add_3 = module.exports = pipe(
() => triple,
() => add_1,
() => add_2
)
...
FAQs
Lazy evaluation + compose
We found that dethunking-compose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.