Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds factory.ChainableModifier #25

Merged
merged 1 commit into from
May 26, 2023
Merged

adds factory.ChainableModifier #25

merged 1 commit into from
May 26, 2023

Conversation

aidenwallis
Copy link
Owner

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.

@aidenwallis aidenwallis self-assigned this May 26, 2023
@aidenwallis aidenwallis merged commit 84e04b8 into main May 26, 2023
@aidenwallis aidenwallis deleted the modifiers-factory branch May 26, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant