March 2019
Intermediate to advanced
208 pages
5h 11m
English
As an alternative to default values, you can use currying with labeled parameters. In the example code we wrote, the default was appropriate for US mortgages. Rather than have one function with a single default, currying lets you create several functions with different values for one or more of the parameters. In this code, we create payment calculation functions for standard mortgage lengths in the US (30 years), UK (25 years), and Germany (20 years):
| | let usPayment = payment(~years=30); |
| | let ukPayment = payment(~years=25); |
| | let dePayment = payment(~years=20); |
| | |
| | let toFixed = Js.Float.toFixedWithPrecision; |
| | |
| | Js.log("Loan of 10000 at 5%" |
Read now
Unlock full access