npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

functionaljs

v0.1.1

Published

functional syntax sugar, for javascript

Downloads

4

Readme

Functional.js

npm

Functional syntax sugar and more, for JavaScript

logo

Why Functional?

1 .Spead up your develop!

2. Build a high-level logic!

3. For fun, isn't it?

Install

Of course. Install by npm with one line

npm install functionaljs

Build

Because ECMAScript 6 Standard has released, so we all use this to build. But not all runtime support the standard.

So, if you use Node.js v5.0.0 or higher, you can use pure *-ec6.js to run. Otherwise use the compiled js(without -ec6) by Babel

You can install Babel through npm and use node-babel instead of node to run example.

sudo npm install -g babel-cli

We recommend to use Sublime Text with Babel plugin. (Which support EC6 and JSX syntax better) and here is a build-system for Sublime in Other/Babel.sublime-build. One short-key Command + Shift + B to run.

Async

What is async Wikipedia About future and promise

  • Async foreach call
var ForEach = require('functionaljs').ForEach;
var fs = require('fs');
var arr = ['/etc/hosts', '/etc/paths', '/etc/donthavethisfile'];

var eachFunc = function (currentValue, index, array) {
	var done = this.async();
	fs.readFile(currentValue, {encoding:'utf-8'}, function (err,result) {
		if (err) {
			console.error('file: ' + currentValue + ' not found');
			done(false); //false to early abort;
		}
		else {
			console.log('file: ' + currentValue + ' load');
			console.log(result);
			done(true); //true to set async have done.
		};
	})
}

ForEach(arr, eachFunc, function () {
	console.log('foreach end');
})

Promise

What is promise? Standard 中文说明

  • Promise

Just use Node.js built-in Promise(from 0.12), or use Promise for ancient version Node.js

  • Promisify

Convert callback function to promise object

var promisify = require('functionaljs').Promisify;
var fs = require('fs');
var readFile = promisify(fs.readFile);
readFile('/etc/hosts', {encoding:'utf-8' ,flag:'r'}).then(function (contents) {
	console.log('promise:\n' + contents);
}).catch(function(error) {
	console.error(error);
});

Monad

What is monad? Wikipedia 中文说明

var Monad = require('functionaljs').Monad;
//Use
var monad = new Monad;
var monad = new Monad(10);

monad.unit(20);
monad.unit(new Monad(30));

monad.bind(function (value) { return value });
var result = monad.bind(function (value) {
	return value.extract() * 2;
})

console.log(result.extract());//60

Optional

What is optional? Wikipedia Optional in Swift

var Optional = require('functionaljs').Optional;
//Use
var op = new Optional(1);

op.present(function (value) {
	console.log(value);//1
});

var result = op.map(function (value) {
	return ++value;
}).map(function (value) {
	return value *= 2;
}).filter(function (value) {
	return value === 4 ? true : false;
}).flatMap(function (value) {
	return new Optional(value);
});

if (result.empty()) {
	result.or(0);
}
console.log(result.get());//4

Curry

What is curry? Wikipedia 中文说明

Attention. Use Function.curry call may be conflict with your custom function curry prototype(if you do so). Please set it to undefined if you don't want

var curry = require('functionaljs').Curry;
//Use by invoking
var multiply = function (a, b) {
	return a * b;
}
var double = curry(multiply, function (args) {
	args.push(2);	//which means multiply(2, x)
	return args;
});

//Use by function prototype
var square = multiply.curry(function (args) {
	args.push(args[0]);	//which means multiply(x, x)
	return args;
})
console.log(multiply(3, 4));//12
console.log(double(3));//6
console.log(square(4));//16

Combinator

What is Y-combinator? Wikipedia 知乎来源

Attention: for strict languages(which means function call by value) such as JavaScript, using original Y-combinator will cause stack overflow because calling f(x(x)) means the compiler(interpreter) will try to generate accuracy defination with infinity stack alloc. So we use Z-combinator to actually implement Y-combinator. For more, see: Z-combinator

  • Y-combinator
/*
We can build a `pure` lambda(anonymous function) with Y-combinator.
See `y-test.js` and learn from step by step what `Y-combinator` is
*/

var Y = require('functionaljs').Y;
var fibonacci = Y(function(f) {
	return function(n) {
		return n == 0 ? 1 : n * f(n - 1);
	}
})
console.log(fibonacci(5))

Lazy

What is lazy? Wikipedia 中文说明

Thanks to @pkrumins

var Lazy = require('functionaljs').Lazy;

//Lazy range
Lazy.range(10).filter(function (e) {
		return e % 2 == 0
	})
	.take(5)
	.map(function (e) {
		return e * 2;
	})
	.forEach(function (e) {
		console.log(e);
	});
//0 4 8 12 16

Retroactive(Data Structure)

What is retroactive? Wikipedia Paper Reference

At now just implement retoractive queue

var retroactive = require('functionaljs').Retroactive;

//partial construct with false or null, fully with true

var partial = new retroactive(false);
var fully = new retroactive(true);

//next use property to generate new object

var partialQueue = new partial.queue();

function partialQueueTest(queue) {
	queue.insert(queue.push(1), 0);
	queue.insert(queue.push(2), 1);
	queue.query();	//[1,2]
	queue.insert(queue.pop(), 2);
	queue.query();	//[2]
	queue.delete(2);
	queue.query();	//[1,2]
	queue.delete(0);
	queue.query();	//[2]
}