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.
factory.ChainableModifier
provides an easy way to produce modifier factory funcs that can generate some output based off of an initial state you define.There's an example in the doc for the function, but this is really useful if you need to test things like validation logic: define your valid input, then use modifiers per test to make the input invalid in some specific way, without rebuilding a struct from scratch each time.
I put some thought into the API, I kind of hate the initial state value requiring a function, but in order to properly support things like pointer values, this is a necessity. It's worth noting this only really works for pointer values too, since not using a pointer will not carry the value to the next modifier. I considered making this API return the new value each time, but that could give the impression that we copy between each modifier, which could lead to unintentional behaviour.
This API works, just use a pointer for values like ints when you put them through the chain, and deref them at the end, if you really need to: though this is only really valuable for things like larger structs.