Functional Programming Part 3 - Implementing Coupon Newsletter System

Practice functional thinking through practical examples

September 17, 2025

The previous post focused on practicing how to distinguish "Actions", "Calculations" and "Data". You can refer to this post Functional Programming Part 2 - Identifying Actions, Calculations and Data, today we'll strengthen our understanding and thinking about actions, calculations and data through practical cases from the book.

Practical Scenario

Email Subscription Table

emailre_count
alice@example.com3
bob@test.com0
carol@demo.org7
david@sample.net12
emma@company.com1
frank@business.io5
grace@startup.co9
henry@tech.org12
iris@digital.com8
jack@online.net4

Coupon Table

couponrank
WELCOME10bad
FRIEND20good
VIP30good
PREMIUM40good
ELITE50best
GOLD60best
PLATINUM70best
DIAMOND80best
MASTER90best
LEGEND100best

For this marketing strategy, list the items that need to be handled and categorize their ACD

ItemACD
Read users from databaseAction
Read coupons from databaseAction
Each coupon's levelData
Single user subscription recordData
Decide user's coupon levelCalculation
Single coupon record listData
User subscription record listData
Coupon record listData
Referral countData
Send newsletterAction
Newsletter titleData
Email addressData
Newsletter contentData

Next, we can break it down step by step, the general process is as follows:

Read subscribers from database to generate subscriber list and read coupons from database to generate coupon list

read subscriber from DB and return a list of subscriber 從資料庫讀取訂閱者資訊進而產生訂閱者清單 read coupons from DB and return a list of coupons  讀取資料庫的優惠碼進而產生優惠碼清單

Generate newsletter sending list

from subscriber and coupons list, then decide newsletter content and a sending list  產生電子報寄送清單

Wait, why is "deciding newsletter content" considered a calculation?

In the above marketing strategy, we can see that the newsletter content will be determined based on the subscriber's referral count to decide whether they get best or good coupons. This decision involves two small calculations:

Through the above, we can decide the newsletter content:

from subscriber and coupons list, then decide newsletter content and a sending list  產生電子報寄送清單

Based on the above, a newsletter content will require the following types of data:

Conclusion

When implementing some features, if we can try to write down the relevant details and first distinguish ACD, then think about whether there's a possibility to break down from A or C. If it can be used as a calculation, it will be easier to test. For me, if it's broken down too finely, it can't really be said to be well managed, but it might be that I don't have enough experience. Therefore, I don't have enough grasp of when to break down and to what extent. The reason I started reading this book is also hoping to learn FP applications and thinking from it, hoping it can help me have a reference basis when thinking.

Back to Blog 🏃🏽‍♀️