curry-rice
Advanced tools
Weekly downloads
Changelog
Readme
TypeScript-first curry function without upcast
A curly function with a strict type definition. There is no upcast to any
types, respecting the typedef of the callback function.
Deno
, Node.js
and Browsers)ES modules
and Commonjs
Deno: curry
(deno.land,
nest.land)
Node.js: curry-rice
(npm)
The origin of the word curry-rice
is Rice and curry 🍛.
const replace = (from: string, to: string, val: string) =>
val.replace(from, to);
const curriedReplace = curry(replace);
curriedReplace("hello", "hi", "hello world"); // 'hi world'
curriedReplace("hello")("hi", "hello world"); // 'hi world'
curriedReplace("hello", "hi")("hello world"); // 'hi world'
curriedReplace("hello")("hi")("hello world"); // 'hi world'
curriedReplace("hello", "hi", "hello world"); // 'hi world'
curriedReplace("hello"); // (to: string, val: string): string
curriedReplace("hello")("hi"); // (val: string): string
curriedReplace("hello", "hi"); // (val: string): string
curriedReplace("hello", "hi", "hello world"); // string
curriedReplace("hello")("hi")("hello world"); // string
curriedReplace("hello", "hi")("hello world"); // string
curriedReplace("hello")("hi", "hello world"); // string
curry
provides multi platform modules.
import { curry } from "https://deno.land/x/curry/mod.ts";
curry(AnyFn);
import { curry } from "https://x.nest.land/curry/mod.ts";
curry(AnyFn);
NPM package name is
curry-rice
.
npm i curry-rice
or
yarn add curry-rice
import { curry } from "curry-rice";
curry(AnyFn);
const { curry } = require("curry-rice");
curry(AnyFn);
The module that bundles the dependencies is obtained from skypack.
<script type="module">
import { curry } from "https://cdn.skypack.dev/curry-rice";
curry(AnyFn)
</script>
declare const curry: <T extends unknown[], R>(
fn: (...args: T) => R,
) => Curried<T, R>;
Parameter | Description |
---|---|
fn | Any function |
=>
The new curried function
const nullary = () => true;
curry(nullary); // () => boolean
const unary = (val: number) => val++;
curry(unary); // (val: number) => number
const binaryFn = (a: number, b: number) => a + b;
curry(binaryFn); // (a: number, b: number) => number || (a: number) => (b:number) => number
This package is focused on getting correct type inference. Hence, there are the following limitations:
19
.Beyond that, the type system will breaks.
Overloads function
cannot be correctly type inferred.Overloads function is something like this:
function len(s: string): number;
function len(arr: any[]): number;
function len(x: any) {
return x.length;
}
For example, it has the following differences from
lodash.curry
.
lodash.curry
has a placeholder feature, which this package does not have.lodash.curry
is any
types, but in
this package, the type of the original argument is inferred.Although placeholders are a useful feature, it is very difficult to implement it while maintaining correct type inference.
If you can solve this issue, please make a pull request.
ie is no longer supported to reduce bundle size.
The TypeScript version must be 4.1.0
or higher.
This project provides ES modules
and Commonjs
.
If you have an opinion about what to support, you can open an issue to discuss it.
The browserslist
has the following settings.
defaults
last 8 version
not IE <= 11
not ie_mob <= 11
node 6
Deno | Node.js | ![]() Edge | ![]() Firefox | ![]() Chrome | ![]() Safari | ![]() iOS Safari | ![]() Samsung | ![]() Opera |
---|---|---|---|---|---|---|---|---|
^1.6.0 | ^6.17.0 | ^83 | ^78 | ^83 | ^11 | ^12.0 | ^7.2 | ^68 |
Contributions, issues and feature requests are welcome!
Feel free to check
issues.
Give a ⭐️ if this project helped you!
Copyright © 2021-present TomokiMiyauci.
Released under the MIT license
FAQs
TypeScript-first curry function without upcast
The npm package curry-rice receives a total of 178 weekly downloads. As such, curry-rice popularity was classified as not popular.
We found that curry-rice 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 installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.