Socket
Socket
Sign inDemoInstall

immutable-sequence

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    immutable-sequence

Immutable sequence


Version published
Weekly downloads
1
Maintainers
1
Install size
51.8 kB
Created
Weekly downloads
 

Readme

Source

immutable-sequence.js

Build Status

High performance implementation of Immutable Sequence in JavaScript, based on Finger Tree.

Installation (Node.js)

npm install immutable-sequence

Then, in your program:

var ImmutableSequence = require('immutable-sequence');

Quick Examples

// Empty sequence
var seq = ImmutableSequence.fromArray([]);
seq.isEmpty(); // true
seq.size(); // 0
seq.peekFirst(); // null
seq.peekLast(); // null
seq.get(0); // throws error

// Nonempty sequence
seq = ImmutableSequence.fromArray(['a', 'b', 'c']);
seq.isEmpty(); // false
seq.size(); // 3
seq.peekFirst(); // 'a'
seq.peekLast(); // 'b'
seq.get(0); // 'a'
seq.get(2); // 'c'

// Add and remove
var seq2 = seq.addFirst('1');
seq2.size(); // 4
seq2.peekFirst(); // '1'

var seq3 = seq.removeFirst();
seq3.size(); // 2
seq3.peekFirst(); // 'b'

var seq4 = seq.addLast('d');
seq4.peekLast(); // 'd'

var seq5 = seq.removeLast();
seq5.peekLast(); // 'b'

// Concatenate two sequences
var a = ImmutableSequence.fromArray([1, 2, 3]);
var b = ImmutableSequence.fromArray([4, 5, 6]);
var c = a.concat(b);
c.size(); // 6
c.peekFirst(); // 1
c.peekLast(); // 6

// Split into two sequences at given index
seq = ImmutableSequence.fromArray(['a', 'b', 'c']);
var split = seq.splitAt(1);
split[0].size(); // 1
split[0].peekFirst(); // 'a'
split[1].size(); // 2
split[1].peekFirst(); // 'b'
split[1].peekLast(); // 'c'

License

MIT License

© 2014 Xueqiao Xu <xueqiaoxu@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 01 Aug 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc