@keienla/functional
v0.11.4
Published
Just a functional library in TypeScript to do Functional Programming
Maintainers
Readme
Functional
Functional is just a library for Functional Programming in TypeScript with optimal tree-shaking support.
Installation
npm install @keienla/functionalUsage
This library is designed with optimal tree-shaking in mind. You can import functions in two ways:
Tree-Shaking Optimized (Recommended)
Import only the functions you need for the smallest possible bundle size:
// Individual imports (best for tree-shaking)
import curry from '@keienla/functional/curry';
import add from '@keienla/functional/add';
import pipe from '@keienla/functional/pipe';
// Usage
const addCurried = curry(add);
const result = pipe(
addCurried(1),
addCurried(2)
)(5); // 8Barrel Import
Import multiple functions from the main entry point:
// Multiple imports from main entry
import { curry, add, pipe, map, filter } from '@keienla/functional';
// Usage
const numbers = [1, 2, 3, 4, 5];
const result = pipe(
filter((x: number) => x > 2),
map(add(10))
)(numbers); // [13, 14, 15]Available Import Paths
For optimal tree-shaking, you can import any function directly:
// Direct function imports
import curry from '@keienla/functional/curry';
import compose from '@keienla/functional/compose';
import map from '@keienla/functional/map';
import filter from '@keienla/functional/filter';
import { _ } from '@keienla/functional/blank';
// Type utilities
import { isString, isNumber } from '@keienla/functional/isType';Tree-Shaking Benefits
This library is configured with:
- ✅ ESM modules for optimal bundler support
- ✅
"sideEffects": falseto ensure safe tree-shaking - ✅ Individual exports for direct function imports
- ✅ TypeScript declarations with proper type inference
When using individual imports, bundlers like Webpack, Rollup, and Vite will only include the functions you actually use, resulting in significantly smaller bundle sizes.
Methods
- add
- and
- arity
- arrayIs
- compose
- constant
- curry
- deepFreeze
- divide
- filter
- filterObject
- flipArgs
- freeze
- gatherArgs
- identity
- is
- isLength
- isnt
- isType
- length
- map
- mapObject
- memoize
- multiply
- nAry
- not
- notSameLength
- objectIs
- or
- partial
- pick
- pickAll
- pipe
- reduce
- reduceObject
- reverseArgs
- sameLength
- spreadArgs
- substract
- transpoline
- type
- unAry
- uncurry
- when
- whenElse
Maybe todo one day
- [ ] Monades
- [ ] Map/Filter function with Transducers?
Build
After npm run build, if want to create a pack folder, go to the dist folder and run "npm pack" -->
