Scala - trying to understand for-comprehension

107 Views Asked by At

I'm still pretty new to Scala, and I'm trying to understand a section of code I came across:

for { 
  _ <- func1() 
  result <- func2() 
} yield result 

func1 and func2 return different types. I'm trying to understand the first line _ <- func1()

It looks to me like it just calls func1() and then drops the result? Does func1() act as a gating mechanism for func2()? That is, if func1() throws an exception, then func2() does not get run? But otherwise, any return value from func1() is thrown away?

0

There are 0 best solutions below