Open In App

Scala | Either

In Scala Either, functions exactly similar to an Option. The only dissimilarity is that with Either it is practicable to return a string which can explicate the instructions about the error that appeared. The Either has two children which are named as Right and Left where, Right is similar to the Some class and Left is same as None class. Left is utilized for the failure where, we can return the error occurred inside the child Left of the Either and Right is utilized for Success.
Example:

 Either[String, Int]

Here, the String is utilized for the Left child of Either as its the left argument of an Either and Int is utilized for the Right child as its the right argument of an Either. Now, let’s discuss it in details with the help of some examples.




Article Tags :