Course of Raku / Advanced / Subroutines / Multiple dispatch / Exercises / Bulk pricing
Solution: Bulk pricing
Here is a possible solution to the task.
Code
multi sub price(Int $qty where $qty >= 10) { say 'bulk price' }
multi sub price(Int $qty) { say 'normal price' }
price(3);
price(25);🦋 You can find the source code in the file bulk-pricing.raku.
Output
normal price
bulk priceComments
The first candidate has a
whereclause that only accepts quantities of 10 or more, so the callprice(25)is dispatched to it.The second candidate has no condition and acts as the catch-all, so
price(3)goes there.
Course navigation
← Bulk pricing | Absolute value →