The first "data-first" and "data-last" utility library designed especially for TypeScript.
npm i remedayarn add remeda
Then in .js or .ts
; // tree-shaking supported!
There are no good utility libraries that work well with TypeScript. When working with Lodash or Ramda you must sometimes annotate types manually.
Remeda is written and tested in TypeScript and that means there won't be any problems with custom typings.
What's "data-first" and "data-last"?
Functional programming is nice, and it makes the code more readable. However there are situations where you don't need "pipes", and you want to call just a single function.
// RemedaR;// RamdaR;// Lodash_;
In the above example, "data-first" approach is more natural and more programmer friendly because when you type the second argument, you get the auto-complete from IDE. It's not possible to get the auto-complete in Ramda because the data argument is not provided.
"data-last" approach is helpful when writing data transformations aka pipes.
const users =name: 'john' age: 20 gender: 'm'name: 'marry' age: 22 gender: 'f'name: 'samara' age: 24 gender: 'f'name: 'paula' age: 24 gender: 'f'name: 'bill' age: 33 gender: 'm'// RemedaR;// RamdaRusers // broken typings in TS :(// Lodashvalue// Lodash-fp_users// broken typings in TS :(
Mixing paradigms can be cumbersome in Lodash because it requires importing two different methods.
Remeda implements all methods in two versions, and the correct overload is picked based on the number of provided arguments.
The "data-last" version must always have one argument less than the "data-first" version.
// RemedaR; // data-firstR; // data-lastR; // error, this won't work!Robj; // this will work but the types cannot be inferred
Many functions support lazy evaluation when using
createPipe. These functions have a
pipeable tag in the documentation.
Lazy evaluation is not supported in Ramda and only partially supported in lodash.
// Get first 3 unique valuesconst arr = 1 2 2 3 3 4 5 6;const result = R; // => [1, 2, 3]/*** Console output:* iterate 1* iterate 2* iterate 2* iterate 3* /
Iterable functions have an extra property
indexed which is the same function with iterator
(element, index, array).
const arr = 10 12 13 3;// filter even valuesR; // => [10, 12]// filter even indexesRfilter; // => [10, 13]
Remeda Design Goals
- The usage must be programmer friendly, and that's more important than following XYZ paradigm strictly.
- Manual annotation should never be required, and proper typings should infer everything. The only exception is the first function in
- E6 polyfill is required. Core methods are reused, and data structure (like Map/Set) are not re-implemented.
- The implementation of each function should be as minimal as possible. Tree-shaking is supported by default. (Do you know that
lodash.keyByhas 14KB after minification?)
- All functions are immutable, and there are no side-effects.
- Fixed number of arguments.