Immutability and immutable js

12
Immutability and immutableJS Marcelo Cure

Transcript of Immutability and immutable js

Immutability and immutableJS

Marcelo Cure

What is Immutability?

Why is immutability good?

● no state changing● easier to test● avoid bugs● safe refactoring● leads to better design

Great powers ...

allocates many objects in memory instead of changing existing ones

...comes with great responsibility

Side effect

If a function mutates an object then it has side effects.

Mutation is side effect.

Immutability and FP

● In FP you should only use immutable stuff● Many languages accept mutation● Hybrid languages accept mutation

Apache Camel example

Exchange is a bitch in a route

Weak vs Strong immutability

Immutable JS

Library with immutable collections

Immutable JS

https://facebook.github.io/immutable-js/