The Eric Normand Podcast

What is a mutation function?

Dec 12, 2022
Ask episode
AI Snips
Chapters
Transcript
Episode notes
INSIGHT

What Mutation Functions Are

  • Mutation functions take current state and an operation, returning a new modified copy without mutating the original.
  • They enable modeling state changes immutably, fitting well with functional programming and event sourcing.
ADVICE

Refactor Mutation Function Arguments

  • Refactor mutation functions to take an operation or event as a single argument for universality.
  • This simplifies handling of different state changes within one function.
ADVICE

Use Mutation Functions with Reduce

  • Use the mutation function as a reducing function over a sequence of operations to apply multiple state changes.
  • This technique efficiently computes the final state from a history of operations.
Get the Snipd Podcast app to discover more snips from this episode
Get the app