A functional programming toolkit for JavaScript.
JavaScript Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.babelrc
.gitignore
.travis.yml
CHANGELOG.md
LICENCE.md
Makefile
README.md
jsdoc.config.json
logo.png
package-lock.json
package.json
rollup.config.js

README.md

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 everyday problems to do with functions, arrays, objects, and strings.

  • FKit treats both strings and arrays as lists, which means you can apply the same list functions to both strings and arrays (e.g. head, tail, map, filter, fold, etc).

  • 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!

Table of Contents

Getting Started

CDN

The quickest and easiest way to start using FKit is to include a reference to the minified file in the head of your HTML file.

You can always grab the latest version with:

<script src="https://unpkg.com/fkit/dist/fkit.min.js"></script>

You can also use a specific version with:

<script src="https://unpkg.com/fkit@1.0.0/dist/fkit.min.js"></script>

Node

Install the npm package:

> npm install fkit

Require it in your code:

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

Or, if you are using ES6 modules, you can import just the bits you want:

import {add} from 'fkit'
console.log(add(1, 2))

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.between(2, 4)) // [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:

Licence

FKit is licensed under the MIT licence. See the LICENCE file for more details.