FKit is a functional programming library for JavaScript. It provides a number of functions and classes, which are sharply focused on everyday utility, for working with strings, arrays, and objects. This provides developers with functional programming "building blocks" that they can use to write better, more expressive code.
Features:
- Why reinvent the wheel? FKit provides many functions for solving common problems with functions, arrays, objects, and strings.
- Most FKit functions are curried by default, so you can partially apply them whenever you need to.
- The ordering of arguments to FKit functions is carefully designed to be more natural, this makes them highly composable.
- FKit treats both strings and arrays as lists, this means you can apply the
same list functions to both strings and arrays (e.g.
map
,filter
, andfold
). - 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
// Stash a string.
F.map(F.surround('{', '}'), 'hello'); // '{h}{e}{l}{l}{o}'
// Add a list of numbers.
F.fold(F.add, 0, [1, 2, 3]); // 6
// Filter a list of numbers where n > 1 and n < 5.
F.filter(
F.whereAll([F.gt(1), F.lt(5)]),
[1, 2, 3, 4, 5]
); // [2, 3, 4]
Check out some more examples:
Download the fkit.js minified library.
Install the npm package:
> npm install fkit
Then require it in your code:
var F = require('fkit');
console.log(F.add(1, 2));
Install the bower component:
> bower install fkit
Build FKit:
> make build
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.