Immutable Stack
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 argumentsvar items = // ImmutableStack can also be initalized with a start stackvar items = items // => ImmutableStack [ 1, 2, 3, 1 ]// ImmutableStack#stack returns the raw arrayitems // => [ 1, 2, 3 ] // The ImmutableStack#push API is exactly the same as Array#pushvar moreItems = itemsmoreItems // => [ 1, 2, 3, 4, 5, 6, 7 ]items // => [ 1, 2, 3 ] // The ImmutableStack#pop API is not the same// Currently, ImmutableStack#pop does not return the popped elementmoreItems // => 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
- Write a new
ImmutableStack#pop()
with signature() -> [ t, ImmutableStack t ]
- Write
ImmutableStack#peek()
for non-destructively getting the head of an ImmutableStack