Suppose I create a function that adds two integers :
def addInt(a : Int, b: Int) : (Int, Int) = {
| val x = a + b
| (x,2)
| }
I'm returning (result, 2)
on purpose for the sake of this question.
Now I want to create a variable that returns only x.
val result = addInt(3,4) for example
result would return (7,2) but I only want it to return 7. How can I do this? (Without changing the code of the function obviously).
val result = addInt(3,4)._1
And if you wanted the 2:
val the2 = addInt(3,4)._2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With