Scala tip - How to include external or legacy code keeping up your code quality
Today, I would like to share a small code tip with you.
We are working on designing a new discount system for an online shop. To calculate our discount we are going to use an external library provided by an external company. The external function is working with integers but in our system we are using strings. How can we integrate them?
In this case, we can parse our parameters from string to integer. However, this process is dangerous, so we are using Either to identify and catch possible errors. Lastly, we can use a map2 function to map the value onto the external function. See the results below:
Related Jobs
Related Articles
Related Issues
- Started
- 0
- 17
- Intermediate
- Submitted
- 1
- 0
- Intermediate
Get hired!
Sign up now and apply for roles at companies that interest you.
Engineers who find a new job through Functional Works average a 15% increase in salary.
Start with GitHubStart with TwitterStart with Stack OverflowStart with Email