Introducing ku.js

24 August 2014

ku.js is a JavaScript library providing functional bindings for everyday JavaScript operations inspired by Underscore and wu.js.

DISCLAIMER: ku is in very early stages of development. Some statements made below are refering to the goal of the project and not the current state of it. It is not recommended to use ku in any production environments yet as it may be unstable.

The project started as an implementation of Brian Lonsdorf’s psuedo-code seen in his talks given at HTML5DevConf last year, “Hey Underscore, you’re doing it wrong!” In this presentation, Brian goes over how Underscore isn’t truly “functional” and the basics of functional programming. The point behind the talk is to show how a truly-composable functional toolset would work in JavaScript, in addition to showing functional programming patterns.

To jump to the point, ku.js intends to be an Underscore alternative that provides a slew of features to aid declarative programming structures:

The obligatory example(s)

var getBanList = function() {
  return Users.fetch().then(function(users) {
    return _.filter(users, function(user) {
      return user.banned;
    });
  }).then(function(users) {
    return _.pluck('username', users).join('\n');
  });
};

beomces

var getBanList = function() {
  Users.fetch()
    .then(ku.filter(ku.attr('banned')))
    .then(ku.pluck('username'))
    .then(ku.method('join', '\n'));
};

or alternatively

var getBanList = function() {
  Users.fetch()
    .then(ku.filter(ku.attr('banned')))
    .then(ku.compose(ku.method('join', '\n'), ku.pluck('username')));
};

If you’re interested, checkout the GitHub repo but outside of this really short blog post there won’t be any documentation until tomorrow.