Skip to content

Repository files navigation

Functional Immutable

Iteratee-first data-last null-safe curried functions wrapper for immutable.js

License: MITnpm: functional-immutablelerna

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.

Installation

Functional Immutable relies on a single peer dependency, it requires Immutable 3 already installed.

npm install --save functional-immutable

Usage

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();// DOE

Also, 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();// DOE

It 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();// DOE

Api Changes

delete => deleteAt

delete being a reserved keyword, the delete method has been re-exported as deleteAt.

Contribute

Something missing?

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);

Test coverage

You can also contribute by writing unit tests, for example by rewriting existing Immutable 3 Unit Tests using functional-immutable.

About

Immutable functional wrapper

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages