score:1
Accepted answer
you can use for-comprehensions to work with option
but you can't use it for objects that don't have at least one defined foreach
, map
or flatmap
. in your case, if params
is returning options then...
for(
input1 <- params get "input1"
input2 <- params get "input2"
){
//do stuff
}
wherein this will not run if both input
and input2
are not none
.
if you don't want to short circuit the control logic and you want there to be sane defaults for option
returns, then a better way is just to do
myfunction(params getorelse ("input1", "default1"), params getorelse ("input2", 42))
where you're explicitly providing the defaults and passing them into a function call.
Source: stackoverflow.com
Related Query
- For iteration on scalatra input
- How to fix the SBT crash: java.lang.NumberFormatException: For input string: "0x100"?
- How can I take any function as input for my Scala wrapper method?
- prompt for user input when running scala program with sbt
- Using Streams for iteration in Scala
- OAuth2 provider for Scalatra or Play framework in Scala
- Scala polymorphic function for filtering an input List of Either
- Monads for Control Flow - Sequence, Selection and Iteration
- How can one change the location of the "webapp" directory for a Scalatra application?
- Scala: Most efficent collection for simple iteration
- Spark job fails on java 9 NumberFormatException for input string ea
- Scalatra test failing using ScalatraSuite (FunSuiteLike) for standlone sbt project
- Which construction for iteration is better to use in Scala?
- How can I supply input for an external command?
- Play Iteratees: error for simple file iteration
- spec2 tests failing for scalatra app with swagger support
- How to define multiple Custom Delimiter for input file in spark?
- Why is the each iteration parameter val and not var in for loop in scala
- Timestamp & Watermark assigning for two input streams, later connected for dynamic alerting using 'EventTime'
- build.sbt - iteration over sub projects for common settings in monorepo
- Function to return the same output for any input in Scala
- Apache Spark K-Means clustering - RDD for input
- Filter function for streaming processor with contravariant input parameter compile error
- Defining a manual Split algorithm for File Input
- How to change jetty port for Scalatra
- Can you dynamically generate Test names for ScalaTest from input data?
- Why doesn't my validation throw exception when it checks for the input type?
- How to write this for iteration in scala without using the For( loop; if condition) and still use yield properlly
- why Partial function in scala is giving run time error for input 0?
- Scalatra Basic Authentication for part of an application
More Query from same tag
- How to practicaly handle List[FieldError] in Lift with Squeryl
- How to generate a random sequence of binary strings of fixed size ( say 36 bits ) in scala
- List[Int] => Int without String Conversion?
- How to install sbt ensime plugin globally?
- Declare a function that doesn't return in Scala
- Browse file and store file url for uploading it later
- How to use IN clause in Slick?
- What does Singleton objects extending a superclass and mix in traits means?
- could not find implicit value for evidence parameter of type org.scalacheck.Arbitrary
- Scala: downcasting throws java.lang.ClassCastException
- org.apache.spark.SparkException: Task not serializable. Scala Spark
- Generic method which works with RDD and Seq
- Spark load model and continue training
- A good way to validate Items in a List Scala
- String include assertion without parentheses with ScalaTest Matchers
- Jackson & Scala: How to get property value from a list of objects by property value?
- Scala what does arrow symbol in sequence mean?
- When doing implicit resolution with type parameters, why does val placement matter?
- How to uncache RDD?
- Why is it that I add ORG.mongodb.smth to dependencies and then import COM.mongodb.smth?
- Scala, regex matching ignore unnecessary words
- matching in scala map to an object
- How to run an Akka-HTTP server inside an Akka cluster?
- Scala compiler reports type mismatch for closure
- What is the best way to find and replace element in immutable set in Scala?
- Akka OneForOneStrategy does not work
- How to make part of Akka ActorSystem synchronous in Typed Akka?
- Get total length of all lists inside a map of tuples
- Jupyter Scala Kernel Missing
- What exactly does 'is more specific than' mean in the context of implicits?