After using Scala for a while and reading about all over the place and especially here
I was sure I know when to use curlies. as a rule of thumb if I want to pass a block of code to be executed i will use curly braces.
how ever this nasty bug surfaced using elastic4s DSL using curly braces:
bool {
should {
matchQuery("title", title)
}
must {
termQuery("tags", category)
}
}
compiles to:
{
"bool" : {
"must" : {
"term" : {
"tags" : "tech"
}
}
}
}
while using parenthesis:
bool {
should (
matchQuery("title", title)
) must (
termQuery("tags", category)
)
}
gives the correct result:
{
"bool" : {
"must" : {
"term" : {
"tags" : "tech"
}
},
"should" : {
"match" : {
"title" : {
"query" : "fake",
"type" : "boolean"
}
}
}
}
}
This was compiled using scala 2.11.6 - Even more confusing is that evaluating the expression in intellij debugger gives correct result no matter what I am using.
I noticed only the last expression was being evaluated why is that?