Skip to content

Persistent Data Structures

kimschles edited this page Apr 16, 2019 · 1 revision

Persistent Data Structures

Lesley Lai, BoulderJS, March 20, 2019

Definitions

  • A persistent data structure
    • Example: git is fully preserved on the disk, and when you make changes and updates, old commits are still there and accessible
    • Old values are preserved
    • First developed as 'imperative data structures'
  • Pure functions From Eric Elliot:
    • Given the same input, will always return the same output.
    • Produces no side effects.
    • You MUST return something
  • Why would you need immutable state?
    • (from Dan) there's less guesswork involved tracing how data came to be in any given state...
    • so errors due to invalid object state should be impossible or easier to isolate for
    • some immutable libs/tooling let you view your state changes over time, almost like time-travel debugging
    • Instead of Immutable, consider Immer
  • Advantages of Persistent Data Structures
    • minimum copying
    • compact history
    • fast comparison

Immutable.js

  • The library is called 'immutable' because it never changes data, it creates a new new set of data with the changes you've applied
  • Lists are called 'stacks' in Immutable.js
Clone this wiki locally