/fkit

A functional programming toolkit for JavaScript.

Primary LanguageJavaScriptMIT LicenseMIT

FKit

Build Status

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, and fold).
  • It's very compact, roughly 3 KB when minified and gzipped!

Documentation

Examples

// 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

Download the fkit.js minified library.

Node

Install the npm package:

> npm install fkit

Then require it in your code:

var F = require('fkit');
console.log(F.add(1, 2));

Bower

Install the bower component:

> bower install fkit

Contribute

Build

Build FKit:

> make build

Test

Run the tests:

> make test

Release

Ship a new release x.y.z:

> make release version=x.y.z

License

FKit is licensed under the MIT license. See the LICENSE file for more details.