refactor: Extract func coerceValue from set and remove func set #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cc @wisepythagoras
Problem
#145 is attempting to follow the current pattern of merging more code paths into
set
, which results in extra conditional complexity inset
in order to essentially determine where it is called from and thus which argument to use.Solution
The common functionality in the
set
function is value coercion, so just extract that to a separate function so that we can get rid ofset
.Note that this makes all of these functions (coerceValue, Set, SetIdx) a lot more readable in isolation. In contrast, the call site for
set
makes it unclear why the placeholder arguments are passed in and theset
function is harder to understand without knowing the context in which it is called from.