Handy if then else function

I came across a need for an inline if/then/else with more than one value to try. If you have only one value, a standard pattern of [something]match[test]then[result]else[otherwise]] but I couldn’t find an easy way to expand that like an elseif. Of course there’s shortcut syntax, but nothing at a filter operator level. Am I wrong? Seems strange I didn’t find anything when searching the forum.

Anyways, this works and I’ll be adding it to my function library unless somebody finds a more natural way to do this. The main benefit is that it’s a if-then that doesn’t destroy the incoming value, so you can chain as many of them as you want. You can do this of course with filter run prefixes (which is how I build the function), but this is much more concise.

\function .ifthen(if,then) [all[]] :map[<currentTiddler>match<if>then<then>else<currentTiddler>]

<$text text={{{ [range[5].ifthen[3],[three].ifthen[5],[five]join[,]] }}}/>

Just something I thought could be helpful to others.

9 Likes