Accepted answer

You can tell the compiler to interpret the block as a function rather than a statement to be called immediately by adding the (in this case lack of) parameters.

So in this case:

def deleteItems(ids: Set[Long]) = {
  context.runInTx {() => ids foreach { dao.delete(_) } }

() => ids foreach { dao.delete(_) } is the full form of the function literal. The compiler allows the parameter list to be omitted in places where it can infer that a function is required - this is true for call by name, but doesn't seem to be true when passing to a method taking a Function

Related Query

More Query from same tag