Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugojosefson/drange-immutable
Wraps drange for functional programming.
https://github.com/hugojosefson/drange-immutable
discontinuous drange functional immutable range
Last synced: 29 days ago
JSON representation
Wraps drange for functional programming.
- Host: GitHub
- URL: https://github.com/hugojosefson/drange-immutable
- Owner: hugojosefson
- Created: 2019-03-02T20:27:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-10T03:26:32.000Z (over 2 years ago)
- Last Synced: 2024-11-06T07:07:19.065Z (about 2 months ago)
- Topics: discontinuous, drange, functional, immutable, range
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/drange-immutable
- Size: 171 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Immutable Discontinuous Range
[![Build Status](https://travis-ci.org/hugojosefson/drange-immutable.svg?branch=master)](https://travis-ci.org/hugojosefson/drange-immutable)
[![npm page](https://img.shields.io/npm/v/drange-immutable.svg)](https://www.npmjs.com/package/drange-immutable)
[![License MIT](https://img.shields.io/npm/l/drange-immutable.svg)](https://tldrlegal.com/license/mit-license)
[![SemVer 2.0.0](https://img.shields.io/badge/SemVer-2.0.0-lightgrey.svg)](http://semver.org/spec/v2.0.0.html)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)Wrapper for the excellent npm package
[`DRange`](https://www.npmjs.com/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 :)```bash
yarn add drange drange-immutable# or
npm install --save drange drange-immutable
```## Usage
```javascript
const range = require('drange-immutable')(require('drange'))
// or
import wrapper from 'drange-immutable'
import DRange from 'drange'
const range = wrapper(DRange)
```Example:
```javascript
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.
```