Closed ghsamm closed 1 year ago
if you look carefully, uniqFuncSequence
does not actually mutate the input array. there are no mutation events, since sliceOut
returns a shallow copy of two portions of the array and ties them together into a new one.
I don't believe there is mutation anywhere else in the repo, but feel free to check 👍
Summary
In this PR, I refactored
uniqFuncSequence
to avoid mutation of the input array. Instead of manipulating the original array, the function now creates a copy using Array.prototype.slice and performs operations on it.Motivation
Mutation of input can lead to unexpected side effects, especially when the function is used in different contexts or when the input is reused later in the code. This change is a step towards enhancing the predictability and purity of functions across our codebase.
Discussion
While this PR focuses on
uniqFuncSequence
, I think it's worth discussing the potential benefits of avoiding mutation throughout the library. This approach could improve readability, predictability, and better adhere to functional programming principles.