ExCellerate.Functions.General.Switch (excellerate v0.4.0)

Copy Markdown View Source

Matches an expression against a series of case/value pairs and returns the value for the first match.

Arguments after the expression are provided in pairs: case1, value1, case2, value2, .... If the total number of remaining arguments is odd, the last argument is used as a default. Returns null if nothing matches and no default is given.

Examples

switch(status, 'active', 'Running', 'paused', 'Paused', 'Unknown')
   'Running' (when status is 'active')
   'Unknown' (when status is 'archived')

switch('B', 'A', 1, 'B', 2, 'C', 3)  2
switch('D', 'A', 1, 'B', 2)           null