Dead simple library for functional and reactive programming

Usage no npm install needed!

<script type="module">
  import fJs from 'https://cdn.skypack.dev/f-js';



Build Status Gitter Stable release Stable release MIT License

Sauce Test Status

F.js is a collection of helper methods used for functional and reactive programming in JavaScript. It provides methods for transforming, filtering, reducing and other operations which work on arrays, HTMLCollections, ES6 generators (and almost all other indexables) and streams of events.


With bower

bower install f.js --save-dev

And include the main script file into your project:

<script src="bower_components/f.js/dist/F.min.js"></script>

With NPM

npm install f-js --save-dev

And require the f-js module into your files:

var Fjs = require("f-js"),
  F = Fjs.F,
  P = Fjs.P;

Manually downloading the zip file

curl "https://codeload.github.com/colin-dumitru/F.js/zip/0.5.0" > F.js.zip
unzip F.js.zip

And include the main script file into your project:

<script src="F.js-0.5.0/dist/F.min.js"></script>



F.js works with regular Arrays (RUN)

var people = [
  { name: "John", age: 31},
  { name: "Colin", age: 25},
  { name: "Dave", age: 13},
  { name: "Vic", age: 52}

var result = F(people)
  .filter(function(person) {
    return person.age < 50;
  .zip(["first", "second"])


HTML collections (RUN)

var links = document.getElementsByTagName("a"),
    titles = document.getElementsByTagName("h5");

var result = F(links)
  .dropWhile(function(val) {
    return val.indexOf("http") == -1;


And even ES6 generators (RUN)

function *gen() {
  for (var i = 0; i < 10; i++) {
    yield i;

var result = F(gen())
  .fold((l, r) => l + r);


So at it's core, F.js is just another functional library. But the real power comes when you combine reactive programming with streams.

Streams are nothing more than promises which can resolve multiple times. You can either push or consume values from a stream, all done asynchronously. This enables you to write more modular async code, by passing values through streams and not callbacks.

This next example takes a search query from an input element and displays a list of images which match the given query, all done using streams.

Stream example (RUN)

var input = $("#search_query"),
    keyStream = F.eventStream(input, "keydown"),
    wordStream = F.stream(),
    imageStream = F.stream();

  .accumulateUntil(P.equalTo(13)) /* Enter */
  .map(function() {
    return input.val();

  .each(text =>
                url: url + text,
                dataType: 'jsonp',
                jsonp: 'jsonFlickrApi',
                jsonpCallback: 'jsonFlickrApi'

  .property("photos", "photo")
  .each(images =>

Got you interested? Visit our wiki pages for more examples and info.