Carlos Hernandez Navarro
29 Jun 2020
•
0 min read
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:
Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ
108 E 16th Street, New York, NY 10003
Join over 111,000 others and get access to exclusive content, job opportunities and more!