FKit (pronounced eff-kit) is a functional programming toolkit for JavaScript. It provides many functions for solving common problems with functions, objects, arrays, and strings. It aims to provide reusable building blocks while maintaining a laser focus on everyday utility.
Features:
- Why reinvent the wheel? FKit provides many functions for solving common problems with functions, arrays, objects, and strings.
- FKit treats both strings and arrays as lists, this means you can apply the
same list functions to both strings and arrays (e.g.
head
,tail
,map
,filter
, andfold
). - Most FKit functions are already curried by default, so you can partially apply them wherever you need to.
- The ordering of arguments to FKit functions is carefully designed to be more natural, this makes them highly composable.
- It's very compact, roughly 3 KB when minified and gzipped!
- API documentation
- Presentation by Josh Bassett: Everyday Functional Programming in JavaScript
- Article by Josh Bassett: Take Your Code to the Next Level with FKit
// Sum the numbers in a list.
F.sum([1, 2, 3]); // 6
// Stash a string.
F.map(F.surround('{', '}'), 'hello'); // '{h}{e}{l}{l}{o}'
// Intersperse the numbers in a list with another number.
F.intersperse(4, [1, 2, 3]); // [1, 4, 2, 4, 3]
// Filter the numbers in a list where 1 < n < 5.
[1, 2, 3, 4, 5].filter(F.whereAll([F.gt(1), F.lt(5)])); // [2, 3, 4]
// Calculate the cartesian product of two lists.
F.cartesian([1, 2], [3, 4]); // [[1, 3], [1, 4], [2, 3], [2, 4]]
// Calculate the permutations of a list.
F.permutations('abc'); // ['abc', 'bac', 'cba', 'bca', 'cab', 'acb']
Check out some more examples:
Download the fkit.js minified library.
Install the npm package:
> npm install fkit
Require it in your code:
var F = require('fkit');
console.log(F.add(1, 2));
Install the bower component:
> bower install fkit
Build the library:
> make production
Run the tests:
> make test
Ship a new release x.y.z:
> make release version=x.y.z
FKit is licensed under the MIT license. See the LICENSE file for more details.