Railo's new default value in structFind()

24 May 2014

That's nowt like getting your hands on a new feature and being able to use it straight away :)

Mapping one value to another is a nice thing to do, setting a default if the key isn't found however makes it less pretty.

Give a map:

  myMap = {   x = 123,   y = 321,   z = 101  };  

Get a mapping or a default if the key isn't there:

  myVar = myMap.find("y", 0);  

What would you have done before?

  if (myMap.keyExists("y")) {   myVar = myMap.y;  } else {   myVar = 0;  }  

Or?

  myVar = myMap.keyExists("y") ? myMap.y : 0;  

That last one isn't so bad.