Search⌘ K
AI Features

Transforming Generators

Explore how to create and transform custom generators in PropEr to generate complex and opaque data structures. Understand the use of macros like ?LET to compose generators efficiently and keep data generation separate from property definitions for clearer, more maintainable tests.

We'll cover the following...

Why transform generators?

To understand why we may need to transform generators, let’s take a look at an example. Using the queue module, we may want to generate a first-in-first-out queue of key/value pairs. Just using tuples and lists won’t be enough to enforce the internal constraints of the data structure. In some cases, the data structure may be opaque, which means that we can’t or shouldn’t look into how it’s built, and rather just stick to the interface the module exposes. This is inconvenient at best. To solve this problem, PropEr exposes macros that let us apply arbitrary transformations to data while the data is generated. ...