Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sorted-immutable-list

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sorted-immutable-list

A sorted immutable list, sorted by a user-supplied comparator

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Sorted immutable list

A helper function for using arrays as sorted immutable lists.

Sorting order is defined using the comparator function, or can be left out to compare the items with < and ==.

Installation

npm install --save sorted-immutable-list

Example usage

import makeAccumulator from 'sorted-immutable-list';

// Setup
const tupleAdd = makeAccumulator({comparator: firstItemComparator, unique: true});

const firstItemComparator = a => b => {
  const x = a[0], y = b[0];

  if (x < y) { return -1; }
  if (x == y) { return 0; }
  return 1;
};

// Use it
const a = tupleAdd([], [4, 'apple']);
const b = tupleAdd(a, [6, 'banana']);
const c = tupleAdd(b, [3, 'carrot']);
const d = tupleAdd(c, [5, 'date']);
const e = tupleAdd(d, [5, 'eggplant']);

// e == [ [3, 'carrot'], [4, 'apple'], [5, 'eggplant'], [6, 'banana'] ]

Licence

MIT. Copyright Roger Nesbitt.

Thanks to Nick Johnstone for being an awesome person from the Internet.

Keywords

FAQs

Package last updated on 22 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc