Scala Language For Expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • for {clauses} body
  • for {clauses} yield body
  • for (clauses) body
  • for (clauses) yield body

Parameters

ParameterDetails
forRequired keyword to use a for loop/comprehension
clausesThe iteration and filters over which the for works.
yieldUse this if you want to create or 'yield' a collection. Using yield will cause the return type of the for to be a collection instead of Unit.
bodyThe body of the for expression, executed on each iteration.


Got any Scala Language Question?