Skip to content

xgrommx/fkit

 
 

Repository files navigation

FKit

Build Status

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, and fold).
  • 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!

Documentation

Examples

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

Download the fkit.js minified library.

Node

Install the npm package:

> npm install fkit

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 the library:

> make production

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.

About

A functional programming toolkit for JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.7%
  • Makefile 1.3%