Skip to content
Functional API for javascript.
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
docs
source
test
.gitignore
LICENSE
README.md
bower.json
gulpfile.js
karma.conf.js
package.json

README.md

Formi

Functional Programming API.

###Status

Codeship

Code Climate

Test Coverage

API Docs

Formi exposes the Formi function.

##Formi(function, args...)

Example

// define predicate function
var not = function(val) {
    return !val;
};

var or = function() {
    return _.some(arguments);
};

Formi(not, true) // ==> false
Formi(or, false, false) // ==> false
Formi(or, false, true, false) // ==> true

##Formi.chain(args...)

Creates a chain for transforming data.

Example

var sum = function() {
    return _.reduce(arguments, function(total, num) {
        return total + num;
    }, 0)
}

var even = function() {
    return _.filter(arguments, function(val) {
        return val % 2 === 0;
    });
}

Formi.chain(1, 2, 3, 4)
    .pipe(even)
    .pipe(sum)
    .value(); // ==> 6

###Formi.chain().pipe(func)

Define function used to transform wrapped data.

###Formi.chain().value();

Return wrapped data

##Formi.compose(funcs...)

Defines a composite function from a series of argument functions.

f(g(h(arg))) === Formi.compose(h, g, f)(arg)

Example

Both of these expamples define the same function.

var sumEven = Formi.compose(even, sum);

var sumEven = function() {
    return Formi.chain(arguments)
        .pipe(even)
        .pipe(sum)
        .value();
}

Formi(sumEven, 2, 3, 4, 5); //==> 6

##Formi.map(func)

Defines a function that applies a function to a set of data

Example

var half = Formi.map(function(num) {
    return num / 2;
});

half(2) //==> 1
half(3, 4) //==> [1.5, 2]
half([4, 8]) //==> [2, 4]

##Formi.reduce(func, [value])

Defines a function that reduces a set of data using a supplied function. A second argument can be provided to define an initial reduction value.

Example

var sum = Formi.reduce(function(total, num) {
    return total + num;
}, 0);

sum(12) //==> 12
sum(3, 4) //==> 7
sum([7, 10]) //==> 17

var even = Formi.reduce(function(arr, num) {
    if (num % 2) {
        arr.push(num);
    }
    return arr;
}, []);

even(1) //==> []
even(1, 2, 3, 4) //==> [2, 4]
even([1, 2, 3, 4]) //==> [2, 4]
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.