Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formi

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formi

Functional Programming API

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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]

Keywords

FAQs

Package last updated on 01 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc