Choose

The 2-modifier Choose (โ—ถ) applies one function from a list ๐•˜, based on the selecting index returned by a function ๐”ฝ. It's a combinator form of Pick (โŠ‘), so that {fโ†(๐•จ๐”ฝ๐•ฉ)โŠ‘๐•˜ โ‹„ ๐•จF๐•ฉ} is a complete definition. For example, the function below subtracts 1 from its argument if negative and adds 1 if positive.

โ†—๏ธ
    0โŠธโ‰คโ—ถโŸจ-โŸœ1, +โŸœ1โŸฉยจ 3โ€ฟยฏ1โ€ฟ5
โŸจ 4 ยฏ2 6 โŸฉ

Here the selection function ๐”ฝ is 0โŠธโ‰ค, while ๐•˜ is a list of two functions โŸจ-โŸœ1, +โŸœ1โŸฉ. On the first argument, 3, ๐”ฝ3 is 0โ‰ค3, or 1, so the function +โŸœ1 from ๐•˜ is chosen. The use of array indices means "false" comes first in ๐•˜ and "true" comes second, which is backwards relative to if-else constructs in most programming languages (including BQN's own predicates). When using a comparison for ๐”ฝ I strongly prefer to phrase it as nโŠธ< or nโŠธโ‰ค so that smaller values go through the first one and larger functions go through the second. This doesn't apply so much when comparing two arguments since one is smaller but the other's larger, so I don't have an easy answer for that.

โ†—๏ธ
    2 >โ—ถโŠฃโ€ฟโŠข 6  # A minimum function (โŒŠ)
2

The advantage of using an index is that Choose works with any number of options.

โ†—๏ธ
    Fn โ† (โŠ‘"rtd"โŠโŠ)โ—ถโŸจโŒฝ, 1โŠธโ†‘, 1โŠธโ†“, โŠขโŸฉ  # Reverse, take 1, drop 1

    Fn "r123"
"321r"

    Fn "d123"
"123"

    Fn "123"  # Default
"123"

The selection function in Fn uses Index of (โŠ) to find the index of the first character in the list "rtd". An extra value in ๐•˜ serves as a default function if it's none of those, since the result of ๐”ฝ is 3 in that case. A similar function that's often useful is Bins, for grouping inputs into intervals rather than by exact matching.

Choose is necessary for tacit programming, but tacit programming is not necessary to be an effective BQN programmer! Consider using block features like predicates when Choose isn't working with your program's flow.

Because Choose is based on Pick, it retains the features of negative, multidimensional, and multiple selection. Negative indexing might make sense if there's some special ยฏ1 value, and if the options naturally form an array, multidimensional indexing is pretty neat. Selecting multiple values from ๐•˜, which happens if the result of ๐”ฝ is an array of arrays, is never useful because the array result from ๐”ฝ acts as a constant function. It's much clearer to express it as ๐”ฝโŠ‘๐•˜ห™.