I’m provided a library with a builder function using default/named params. Something like
def builder = new {
def apply(
a:Int = 0,
b:Int = 0,
c:Int = 0):String = {
"a="+a+", b="+b+", c="+c
}
}
I need to consume a Mapped Collection of parameters (http query params) and call the builder properly. I can brute force it with repetitive code but there must be a better “functional” way to do this. Below is my rather poor attempt. As you can see it overrides the builder’s default params. Please show me the light!
val inParams = Map("a" -> 1, "b" -> 2, "c" -> 3) //3 params passed in
builder(
in.get("a").getOrElse(0),
in.get("b").getOrElse(0),
in.get("c").getOrElse(0)
)
val inParams = Map("a" -> 1, "c" -> 3) //2 params, out of sequence
builder(
in.get("a").getOrElse(0),
in.get("b").getOrElse(0),
in.get("c").getOrElse(0)
)
Maphas agetOrElsemethod.Or you can also do: