score:11
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
Source: stackoverflow.com
Related Query
- Is there any analog for Scala 'zip' function in Groovy?
- Is there a standard Scala function for running a block with a timeout?
- Is there a lambda function in Scala?
- Is there a function in scala or scalaz to apply a function to a list if the list is not empty?
- Is there a way to call a function defined using `val` in Scala with the whole curly brace block as an argument and not the final result of that block?
- Is there a way to specify the return type of an Scala function literal?
- Scala compiler failed to infer type inside Spark lambda function
- Can't override scala abstract function with lambda
- How to use java8 lambda and function in scala
- Scala lambda function not resolved when declares the type of parameter?
- Is there exponential function in scala
- Scala - Confusion with lambda in map function
- Is there a Scala function of type `Nothing => A`? Or how to construct one?
- Scala lambda function with map function
- Why is Scala unable to infer the type of an anonymous function when there is method overloading and only one method takes a function?
- scala lambda function and local variables
- How to get a type in Scala AST of underscored lambda function parameter?
- Scala function overrides with lambda parameters
- Why is there different behavior for `.split` function in REPL and scala compiler
- Scala lambda in function args
- Is there any relation between Curried function/ Partially applied function and Higher order functions in scala
- Scala - Is there a function to map Seq[A] => Seq[Either[Throwable, B]]?
- Is there a function in scala used to remove items from a list?
- Is there a scala spark function to achieve the groupby then filter and then aggregate
- Is there a way in scala for printing the size of a list beetween a function chaining?
- scala function not called from lambda function
- Difference between method and function in Scala
- What's the standard way to work with dates and times in Scala? Should I use Java types or there are native Scala alternatives?
- What is the Scala annotation to ensure a tail recursive function is optimized?
- Defining a function with multiple implicit arguments in Scala
More Query from same tag
- how to construct Scala API with error sentinel token (like Option.None) that can be chained through flatmap?
- Gatling - randomize scenario's request order?
- console log4j2 kafka: No appenders could be found for logger (kafka.utils.Log4jControllerRegistration$)
- Streaming Predictions in Apache Flink
- Application won't exit after downloading a file with scala-ssh
- scala - sum up map's value by position
- Sending post with json using spray?
- Selecting all the rows between Two specific Strings in DataFrame Column using Scala Spark
- Scala: abstract classes with anonymous types
- How to set heap size for sbt?
- Removing duplicate rows based on Java DataFrame
- In Scala, is it possible to instantiate an object of generic type T?
- Spark/Scala: Operations on some components from a DataFrame with Array typed column
- Scala: Most concise conversion of a CSS color string to RGB integers
- Evaluating an expression of type shapeless.Witness.Aux[T] in a macro fails
- How to extend an existing sbt task with a custom dependency?
- Play Json: custom reads one field
- How to get item id from cosine similarity matrix?
- There is a HTTP server starts when Launching Spark jar on a machine, what's that?
- Tail recursion issue
- How to move all files in a directory to another in hadoop
- value toDF is not a member of Seq[(Int,String)]
- Getting random maps from generator code in Scala
- Play Framework template, iterate backwards over List
- Assertion failed when compiling Scala in IntelliJ
- "conditionalZip" operator in Akka Streams
- Reading data into custom case classes in Doobie
- FlywayDB: Migration fails with "Error executing statement", but manually running migration SQL code works
- sbt Resolve Error in Intellij
- How to put data from various tables into separate lists via one request