Business Rules as Pure Functions
Keep logic testable by avoiding platform side effects.
What Is a Pure Function
A pure function returns the same output for the same input and touches nothing outside itself. That makes it perfect for shared code.
No Hidden Side Effects
Pure means no logging, no network, no saving to disk. The function just takes values in and gives a result back.
fun shippingFee(weight: Double): Double = if (weight > 5) 9.0 else 4.0All lessons in this course
- A Shared Price & Tax Calculator
- Format Currency & Numbers
- Business Rules as Pure Functions
- Keep UI Out of Shared Code