0.0.3 • Published 10 years ago

fun-js v0.0.3

Weekly downloads
11
License
-
Repository
-
Last release
10 years ago

fun-js

Build Status

Functional Programming for Javascript

install

node

$ npm install fun-js

browser

Drop fun.js into your project and see usage below.

test

$ ./test

See project page for test suite output.

usage

Note: fun-js adds a method called 'autoCurry' to Function.prototype

node.js

var assert = require("assert");

// import *everything* into the global context
var fun = require("fun-js").import();

// Currying
var findBrians = filter(function(person) {
    return person.name === "Brian";
});
assert.strictEqual(typeof findBrians, "function", "filter can be curried");

// Composition
var hasBrian = compose(compose(not, empty), findBrians);
assert.strictEqual(typeof hasBrian, "function", "compose creates new functions from old ones");

var beatles = [
    { name : "John" },
    { name : "Paul" },
    { name : "George" },
    { name : "Ringo" },
    { name : "Brian" }
];

assert(hasBrian(beatles), "Brian is a legendary rock star");

// Another way of making a hasBrian function...
var isBrian = compose(identical("Brian"), pluck("name"));
var hasBrian2 = compose(isDefined, find(isBrian));
assert(hasBrian2(beatles), "double-checking that Brian is a legendary rock star");

browser

// global reference stored under window.fun...
// selectively import 'curry' and 'compose' into the global context
fun.import({
    select: [
        "curry",
        "compose"
    ]
});

if (typeof curry !== "function" || typeof compose !== "function") {
    throw new Error("fun-js could not selectively import curry and compose");
}
    

more info

project page

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

11 years ago