Giter Club home page Giter Club logo

drange-immutable's Introduction

Immutable Discontinuous Range

Build Status npm page License MIT SemVer 2.0.0 JavaScript Style Guide

Wrapper for the excellent npm package DRange.

This wrapper keeps the exact same API syntax as DRange, except:

  • each method that mutates the range, instead returns a mutated clone,
  • the range is also sorted after .add() is used, instead of putting loose ranges at the end.

The immutability makes it fit better with a purely functional code style.

Installation

You need to install drange yourself, so you can upgrade to newer versions without me having to upgrade this wrapper too :)

yarn add drange drange-immutable

# or

npm install --save drange drange-immutable 

Usage

const range = require('drange-immutable')(require('drange'))
 // or
import wrapper from 'drange-immutable'
import DRange from 'drange'
const range = wrapper(DRange)

Example:

const hundred = range(1, 100)
console.log(hundred.toString())        // [ 1-100 ]

const split = hundred.subtract(50, 60)
console.log(split.toString())          // [ 1-49, 61-100 ]
console.log(hundred.toString())        // [ 1-100 ]
                                       //   ^^ still the same.
                                       //   Original drange would have
                                       //   mutated 'hundred' too. 

drange-immutable's People

Contributors

dependabot[bot] avatar hugojosefson avatar

Watchers

 avatar  avatar

drange-immutable's Issues

Test longer chain

Test a longer chain of mutations, so we know the Proxying is done correctly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.