immutable-stack

1.0.1 • Public • Published

Immutable Stack

Build Status

An array-wrapper that provides immutable push and pop operations.

Author

Jordan Timmerman (@skorlir) at the Northwestern University WCAS Multimedia Learning Center (MMLC)

License

ISC

Usage

 
// Initialize an ImmutableStack just by calling ImmutableStack without arguments
var items = ImmutableStack()
 
// ImmutableStack can also be initalized with a start stack
var items = ImmutableStack([ 1, 2, 3 ])
 
items.push(1) // => ImmutableStack [ 1, 2, 3, 1 ]
// ImmutableStack#stack returns the raw array
items.stack() // => [ 1, 2, 3 ]
 
// The ImmutableStack#push API is exactly the same as Array#push
var moreItems = items.push(4, 5, 6, 7)
moreItems.stack() // => [ 1, 2, 3, 4, 5, 6, 7 ]
items.stack()     // => [ 1, 2, 3 ]
 
// The ImmutableStack#pop API is not the same
// Currently, ImmutableStack#pop does not return the popped element
moreItems.pop()   // => ImmutableStack [ 1, 2, 3, 4, 5, 6 ]
 
// The use case for which ImmutableStack was written doesn't require that functionality
// But it would be possible to build it in
 

Next

Either

  1. Write a new ImmutableStack#pop() with signature () -> [ t, ImmutableStack t ]
  2. Write ImmutableStack#peek() for non-destructively getting the head of an ImmutableStack

Package Sidebar

Install

npm i immutable-stack

Weekly Downloads

0

Version

1.0.1

License

ISC

Last publish

Collaborators

  • fluffywaffles