In Kustom, if() treats "" and 0 as false, and everything else as true. & and | treat 1 as true and everything else as false. Additionally, when given one or two string arguments, these operators concatenate both their sides with the operator symbol in the middle, i.e. "a" | "b" -> "a|b".
I propose & and | should work like && and || do in Javascript. They should treat "" and 0 as false, everything else as true (would make them consistent with if()).
| would return the first non-falsy argument it is given, or the last argument if all are falsy:
0 | a -> a
0 | "" -> ""
"" | 0 -> 0
0 | "" | a -> a
a | b | c -> a
& would return the first falsy argument it is given, or the last argument if all are truthy:
0 & a -> 0
0 & "" -> 0
"" & 0 -> ""
a & b & 0 -> 0
a & b & c -> c
This enables easy default values:
instead of
if(bp(vibrant, mi(cover)), bp(vibrant, mi(cover)), #FFFFFF)
you’d simply write
bp(vibrant, mi(cover)) | #FFFFFF
I’m sure more interesting uses for this would be found too, but just the default values and consistency with if() are worth it, in my opinion.
EDIT: Simple solution for returning 0 instead of dividing by 0:
#divby & (#number / #divby)
If #divby is 0, the & returns 0. Otherwise the result of the division is returned.
EDIT: Concatenating text with additional decorations only if it isn’t empty:
"segment" + (#text & " - " + #text) + " - another segment"