Transforming Generators
Understand the reasons to transform generators and how to use the ?LET macro.
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.
To illustrate the issue, let’s take a look at the queue module. Suppose we wanted to have a queue of keys and values stored as tuples. In that case, we couldn’t safely create it out of default generators without digging inside the implementation and understanding how all the data is handled internally.
Our basic use of the queue
module would look like this:
Get hands-on with 1400+ tech skills courses.