Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Executing side effect code inside scala for-comprehension block

How can I execute a side-effect code inside for-comprehension block? If I have something like this:

for {
 data <- fetchData()
} yield data.someAttribute

…and now I want to execute some code using foreach

for {
     data <- fetchData()
     someList <- fetchList(data)
     somelist.foreach(....)
} yield data.someAttribute

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Simply:

for {
     data <- fetchData()
     someList <- fetchList(data)
     _ = somelist.foreach(....)
} yield data.someAttribute
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading