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

There should be a way to compose generators with filters #138

Open
ionelmc opened this issue Jul 24, 2021 · 0 comments
Open

There should be a way to compose generators with filters #138

ionelmc opened this issue Jul 24, 2021 · 0 comments

Comments

@ionelmc
Copy link

ionelmc commented Jul 24, 2021

Maybe I'm missing something but something like this should be builtin:

def COMPOSE(generator: ServiceValue, *callables):
    class Generator(ServiceValue):
        def gen_value(self, type_mixer, name, field):
            field, value = generator.gen_value(type_mixer, name, field)
            for func in callables:
                value = func(value)
            return field, value
    return Generator()

eg: mixer.blend(MyModel, field=COMPOSE(mixer.RANDOM, str.upper))

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

No branches or pull requests

1 participant