Implementing the Rest of the Steps

Now that we’ve seen how to implement validateOrder, we can use the same techniques to build the rest of the pipeline functions.

Here’s the original design of the pricing step function, with effects:

 type​ PriceOrder =
  GetProductPrice ​// dependency
  -> ValidatedOrder ​// input
  -> Result<PricedOrder, PlaceOrderError> ​// output

But again, we’ll eliminate the effects for now, leaving this design:

 type​ GetProductPrice = ProductCode -> Price
 type​ PriceOrder =
  GetProductPrice ​// dependency
  -> ValidatedOrder ​// input
  -> PricedOrder ​// output

And here’s the outline of the implementation. It simply transforms each order line to a PricedOrderLine and builds a new PricedOrder with them:

Get Domain Modeling Made Functional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.