Hyperon concepts

Functions

Another key concept that helps to move business logics out of application is function. Functions enable you to write code snippets in regular programming language, which let you implement any logic you want. You can write functions where parameter matrix is not enough.

As in the case of parameters, functions can contain logic based on:

  • any element from context,
  • any defined parameter,
  • any defined function.

Below you can see sample function that uses context data and depends on parameter:

var age = ctx.getNumber( 'client.age' );            // reads client's age from context

var factor = 1.8;
if (age > 65) {
  factor = math.log(10, age);
}

var tariff  = hyperon.getNumber('tariff', ctx);     // get value from tariff parameter
var baseFee = hyperon.getNumber('base.fee', ctx);   // get value from base.fee parameter

var fee = baseFee * tariff * factor;

return math.round(fee, 2);                          // return fee rounded to 2 digits

Hyperon functions give you convenient API to:

  • handle context,
  • read parameters,
  • call other functions,
  • operate on dates and strings,
  • perform math operations,
  • perform type conversions,
  • log statements to log file,
  • use domain objects.

Following image shows another function defined in Hyperon Studio.

Functions use JavaScript syntax with some Hyperon extensions that make life easier. See Using functions for more details.