Curry
:curry: Currying made simple.
Install / Use
/learn @thisables/CurryREADME
Currying made simple.
– and we really mean simple:
import {curry, _} from '@thisables/curry';
// Got a simple function?
const plus = (
(a, b, c) => a + b + c
)::curry();
plus(1, 2, 3); //» 6
plus(1)(2, 3); //» 6
plus(1, 2)(3); //» 6
plus(1)(2)(3); //» 6
// Got a monster function?
const {open} = require('fs');
const newScript = open::curry(_, 'w', 0755, _);
newScript('do-wonders.sh', (error, file) => {
// The `file` is ready.
});
Installation
npm install @thisables/curry
Usage
Basic usage
The function curry is invoked using the function bind syntax and returns a curried function.
const add = (a, b) => a + b;
const curriedAdd = add::curry();
curriedAdd(1)(2); //» 3
Placeholders
A placeholder _ is a special value, which you import from 'curry-this'.
Placeholders are replaced from left to right, the next call after a placeholder is passed replaces the previous placeholders one by one.
const foo = (a, b, c, d) => [a, b, c, d];
const curriedFoo = foo::curry(_, _, _, 4);
curriedFoo(1)(2)(3); //» [1, 2, 3, 4]
If you pass a placeholder to curry the length of the function is ignored instead the initial call of curry defines the length of the curried function.
const foo = (...values) => values;
const curriedFoo = foo::curry(_, _, _);
curriedFoo(1)(2)(3); //» [1, 2, 3]
Arity
The curried function has a fixed arity. Additional arguments aren't passed.
const foo = (...values) => values;
const curriedFoo = foo::curry(_, _, _);
curriedFoo(1)(2)(3, 5, 6, 7); //» [1, 2, 3]
Not experimental usage
You can still use curry without the experimental syntax
const add = (a, b) => a + b;
const curriedAdd = curry.call(add);
curriedAdd(1)(2); //» 3
Or with placeholders
const foo = (...values) => values;
const curriedFoo = curry.call(foo, _, _, _);
curriedFoo(1)(2)(3); //» [1, 2, 3]
API
fn::curry(...args)
Parameters
fn | the function to curry -------|---------------------- args | curried arguments or placeholders
Returns
A curried function.
:: huh?
If you’re wondering what the :: thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal.
Maintainers
| |
|
| :--:|:--: |
| stoeffel | tomekwi |
License
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
