How to deal with zero?

Report a typo

We wrote a function to divide two integers, but it turned out to be unsafe with zero arguments. Refactor the function using Either and return Division by 0 for problematic arguments.

Sample Input 1:

8
0

Sample Output 1:

Left(Division by 0)
Write a program in Scala 3
def safeDivide(x: Int, y: Int): Int =
(x / y)
___

Create a free account to access the full topic