nb-simple-fp

0.4.0 • Public • Published

nb-simple-fp

Super simple fp helper, only two methods

  • curry
  • monad

Installation

$ npm install nb-simple-fp --save

Or Browser (an UMD version)

$ bower install nb-simple-fp --save

Please note, we use the jsnext:main for the ES6 version. Please check rollup for information

API

Recommend you start using ES6 Javascript now:

curry

import {curry} from 'nb-simple-fp';

/**
 * some practical examples 
 * they are from my other library nb-immutable-model 
 */

import _ from 'lodash';


const checkKey = curry( function(method , param)
{
	if (!method(param)) {
		throw 'Expect key to be string!';
	}
	return true;
},
_.isString);


// this is especially useful to setup some opion based methods 
 
const setupStorage = function(key = 'local')
{
	// the key can be local or session
	
	// some check here obmitted ... 
	

	this.engine = curry( function(storage , method , ...params)
	{
		
		return storage[method](...params);
	}, window[key+'Storage']);	
};

// now to to use it 

this.engine('setItem' , this.checkKey(key) , dataToStore); // you get the idea 

There is no limit of how many parameter you need to pass, as long as you pass the enough parameter to your function (pre-curried function) then it will executed.

maybe monad

The code is based on James Sinclair excellent article THE MARVELLOUSLY MYSTERIOUS JAVASCRIPT MAYBE MONAD.

The different is this library is written in ES6 Javascript and ready to use with rollup.

import {Maybe} from 'nb-simple-fp';

// ... TBC 

Joel Chu (2016) London

Package Sidebar

Install

npm i nb-simple-fp

Weekly Downloads

1

Version

0.4.0

License

MIT

Last publish

Collaborators

  • joelchu