@7urtle/lambda
Functional programming library for JavaScript

Enjoy programming in JavaScript by writing elegant functional code with brilliant reusability, high-speed performance, and effortless testability. @7urtle/lambda gives you everything from basic functional utilities to badass monads.

Focus on your own skill level

@7urtle/lambda was written to help you transition towards functional programming no matter your skill level. You can pick up any functional features as you learn at your own pace. At the end you can master everything including pure functions, composition, currying, functors, and monads.

Shorter and faster code

The combination of @7urtle/lambda and modern JavaScript syntax for functional programming leads to more concise code with high reusability.

Declarative code can be expected to be much shorter thanks to its inherent simplicity and the functional method of memoization delivers effortless caching. In the end you have shorter and faster code.

See examples and comparisons of code ›

1
import {memo, isZero} from '@7urtle/lambda';
2
3
// recursive factorial using memoization for performance increase
4
const factorial = memo(n => isZero(n) ? 1 : n * factorial(n-1));
5
6
factorial(6); // => 720

Functors and Monads

Monads from @7urtle/lambda allow you to achieve functional purity by giving you universal method for controlling synchronous and asynchronous side effects as well as better manage your error states.

See examples of monads in action ›

1
import {Maybe, map, compose}
2
from '@7urtle/lambda';
3
4
const selectMaybeDOM = selector =>
5
Maybe.of(document.querySelector(selector));
6
const getOffsetTop = element =>
7
element.offsetTop;
8
const getPositionFromTop =
9
compose(map(getOffsetTop), selectMaybeDOM);
10
11
getPositionFromTop('#imayexist');

Testability and safety

Pure functions created with functional programming and @7urtle/lambda are easy to test because they don't create side effects and are dependent only on its input. You avoid difficult mocking and easily achieve 100 % coverage.

See examples of testing strategies ›

1
import {upperCaseOf, trim, compose, map, Maybe}
2
from '@7urtle/lambda';
3
4
const transformer = compose(trim, upperCaseOf);
5
const transformData = map(transformer);
6
7
test('Runs trim and upperCaseOf.', () => {
8
expect(transformer(' input ')).toBe('INPUT');
9
});
10
11
test('Maps transformer to a monad.', () => {
12
const input = Maybe.of(' input ');
13
expect(transformData(input).value).toBe('INPUT');
14
});

Get Started

Install @7urtle/lambda with NPM or add it directly to your website.