fakedata
fakedata copied to clipboard
Reading the generator from environment?
Currently, the value of the deterministic generator is nailed down in FakerSettings. It is used in the function generateWithSettings.
I propose that this function checks if:
- A certain environment variable is set.
- It parses to a number.
- The value of the generator in the given settings is default.
- The mode of generation is deterministic.
— And if all are true, the value of the parsed environment variable is used as the generator instead of the default value.
The goal is to make it possible to adjust the generator in a convenient way. Of course there are already ways to adjust the generator, but they all require passing it around the code one way or another, which is rather inconvenient.
This change is conservative and backwards compatible. I can write the code and make a pull request.
Sounds interesting. What do you think about introducing a new function instead which has the above behaviour you describe:
generateWithEnvSettings :: FakerSettings -> Fake a -> IO a
I'm slightly concerned about the additional IO done for each call to generateWithSettings. What do you think ?
This is a valid concern. I have not measured the cost of access to environment variables — I imagine it to be small but who knows. On the other hand, introducing this new function will result in some code duplication — I cannot see a way to express any one of generateWithSettings and generateWithEnvSettings in terms of the other. Whichever works for you is fine by me!
On the other hand, introducing this new function will result in some code duplication — I cannot see a way to express any one of generateWithSettings and generateWithEnvSettings in terms of the other.
I guess that's fine. :-)
Alright then, I shall do this within a few days.