Understanding and Decoding the anyeach Function in kdb+/q

Hi everyone,

I’m trying to deconstruct a somewhat cryptic kdb+/q function written by a senior developer at my company. Here’s the function:

anyeach:{[c;v] enlist (each; any; ((:; in); ($; enlist `; (each; { $[“;” in x; “;” vs x; x] }; ($:; c))); (enlist v)))}

I am using like this:

t:( column:(“aaa;bbb”; “aaa”; “ccc;bbb;ddd”));
val:“aaa”;

Here, column is passed as c, and val as v.

My goal is to better understand how the function works—what each part does, step by step. Please help me.

Hi Kaviya, it’s likely a typo (or a formatting glitch), should be (\:;in). With t`column and val also fixed by casting them to symbols. Without a usage example, it is hard to confirm but the function seems to be the following filtering

q)?[t;anyeach[`column;val];0b;()]
column
-------
aaa;bbb
aaa