Working with Simple Types
Before we start implementing the steps of the workflow itself, we need to first implement the “simple types,” such as OrderId and ProductCode.
Since most of the types are constrained in some way, we’ll follow the outline for implementing constrained types discussed earlier.
So, for each simple type we’ll need at least two functions:
-
A create function that constructs the type from a primitive such as string or int—for example, OrderId.create will create an OrderId from a string, or raise an error if the string is the wrong format.
-
A value function that extracts the inner primitive value
We typically put these helper functions in the same file as the simple type, using a module with the same name as the type they apply ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access