This is a tutorial on functional programming in Scala with cats, cats-effect and fs2.
- Type
sbtto enter the sbt console. - Run the application with
run 12. This should draw a 12 inch pizza with a single olive (you'll need to use your imagination here).
Take a look inside the pie.PizzaShop to see what gets run.
Create an algebraic data type Pizza with a size and a sauce.
- The size should be a number.
- The sauce should be
BechamelorTomato
Take a look at the tests in ValidateSizeTest. Write a function validateSize that:
- takes a pizza size as an argument
- evaluates to either a pizza or an error
The error must be one of:
NegativeSizePizzaTooBigPizzaTooSmall
Write a function correction. As an argument, it should take in an error.
- takes an error as an argument
- If the error is a
PizzaTooBigerror, it evaluates to a 16 inch pizza - If the error is a
PizzaTooSmallerror, it evaluates to a 3 inch pizza - If the error is none of the above, it evaluates to that same error
Write a function validateSauce that:
- takes a sauce name as an argument
- evaluates to either
Bechamel,Tomatoor aStrangeSauceerror
Use a Validated to evaluate both vaildateSize and validateSauce.