Q13. What are the different approaches in Scala to solve the following task?
Given numbers 1 to 6, and you need to extract out the odd numbers and double them, and finally print the result.
A13. There are 3 ways to solve the problem.
…
Q13. What are the different approaches in Scala to solve the following task?
Given numbers 1 to 6, and you need to extract out the odd numbers and double them, and finally print the result.
A13. There are 3 ways to solve the problem.
…
Example #10: Null checks with “Option-Some-None”
Nulls in Scala is a code smell, and a better way to handle null values is with an “Option“, which has 2 sub classes “Some” that has a value and a “None”
…
Q19. What is the use of Tuples in Scala? A19. A Tuple is an immutable collection that can hold objects of different types. In other words, it groups together logical collections of items without using a class. There are 22 Tuple class in Scala from Tuple1, … Read more ›...
Example #13: Explain the concepts
Can you explain the Scala concepts applied in the following code snippets?
1. Higher Order Functions: “Line 10” is a higher order function as the function returns another function i.e. List[T] =>
…
Java has idioms like Try-Catch-Finally, Scala has idioms like 1) “Option-Some-None”, 2) Either-Left-Right 3) Try-Success-Failure. Q27. How does Scala try to solve the problem of getting rid of null values & the “NullPointerException”? A27. Scala provides its own type for representing optional values with “Option[A]”, … Read more ›...