Iteratee-first data-last null-safe curried functions wrapper for immutable.js
Are you using Immutable.js with React and Redux? Take a look at react-redux-immutabe for mapping your immutable state to your props without performance hit.
Functional Immutable relies on a single peer dependency, it requires Immutable 3 already installed.
npm install --save functional-immutable
Functional Immutable aims to provide all immutable object methods as curried, data-last, null-safe functions. It is designed to work seamlessly in an point-free style program.
For example :
importfpfrom"lodash/fp";importImmutablefrom"immutable";import*asfifrom"functional-immutable";constimmutableObject=Immutable.fromJS({user: {lastName: "Skywalker"}});exportconstgetUppercaseLastName=fp.flow(fi.getIn(['user','lastName']),fp.defaultTo('Doe'),fp.toUpper,);getUppercaseLastName(immutableObject);// SKYWALKERgetUppercaseLastName();// DOEAlso, Functional Immutable is non-opinionated and will work with any point-free library such as Ramda.
importRfrom"ramda";importImmutablefrom"immutable";import*asfifrom"functional-immutable";constimmutableObject=Immutable.fromJS({user: {lastName: "Skywalker"}});exportconstgetUppercaseLastName=R.compose(R.toUpper,R.defaultTo('Doe'),fi.getIn(['user','lastName']),);getUppercaseLastName(immutableObject);// SKYWALKERgetUppercaseLastName();// DOEIt should also shine with Redux selectors such as reselect or re-reselect.
import{createSelector}from"reselect";importImmutablefrom"immutable";import*asfifrom"functional-immutable";constapplicationState=Immutable.fromJS({user: {lastName: "Skywalker"}});exportconstgetUppercaseLastName=createSelector(fp.flow(fi.getIn(['user','lastName']),fp.defaultTo('Doe')),fp.toUpper);getUppercaseLastName(applicationState);// SKYWALKERgetUppercaseLastName();// DOEdelete being a reserved keyword, the delete method has been re-exported as deleteAt.
Found a missing function? Feel free to contribute by opening a Pull Request.
This wrapper relies on naïve re-exports of Immutable object methods. Here is how to add a missing method called missing.
In index.js add the following:
exportconstmissing=(...vargs)=>data=>safeApply(data,'missing',vargs);You can also contribute by writing unit tests, for example by rewriting existing Immutable 3 Unit Tests using functional-immutable.