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.
1import {memo, isZero} from '@7urtle/lambda';23// recursive factorial using memoization for performance increase4const factorial = memo(n => isZero(n) ? 1 : n * factorial(n-1));56factorial(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 ›
1import {Maybe, map, compose}2from '@7urtle/lambda';34const selectMaybeDOM = selector =>5Maybe.of(document.querySelector(selector));6const getOffsetTop = element =>7element.offsetTop;8const getPositionFromTop =9compose(map(getOffsetTop), selectMaybeDOM);1011getPositionFromTop('#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 ›
1import {upperCaseOf, trim, compose, map, Maybe}2from '@7urtle/lambda';34const transformer = compose(trim, upperCaseOf);5const transformData = map(transformer);67test('Runs trim and upperCaseOf.', () => {8expect(transformer(' input ')).toBe('INPUT');9});1011test('Maps transformer to a monad.', () => {12const input = Maybe.of(' input ');13expect(transformData(input).value).toBe('INPUT');14});