[KDB+/Q]:按顺序在数据上应用函数列表(管道)

[KDB+/Q]: Apply list of functions over data sequentially (pipe)

在 kdb+/q 中,如何通过顺序函数列表传输数据,以便上一步的输出是下一步的输入?

例如:

q)t:([]sym:`a`c`b;val:1 3 2)
q)`sym xkey `sym xasc t                / how to achieve the same result as this?

我假设 over/ 的某些变体可以工作:

   ?? over (xasc;xkey)

奖励: 如何以 t 从右侧管道输入的方式实现相同的效果(本着 的精神右左 阅读 q 语法)?

(xasc;xkey) ?? t

在左边使用 lambda 以及 over 副词(递归形式) apply 的点 (.) 形式也用于将函数应用于 table 和列:

  {.[y;(z;x)]}/[t;(xasc;xkey);`sym]
  sym| val
  ---| --- 
  a  | 1
  b  | 2
  c  | 3

how to pipe data through a sequential list of functions so that output of previous step is the input to next step?

可以使用鲜为人知的composition operator。例如:

q)f:('[;])over(2+;3*;neg)
q)f 1 # 2+3*neg 1
-1

如果你想使用 left of right 语法,你必须定义你自己的动词:

q).q.bonus:{(('[;])over x)y}
q)(2+;3*;neg)bonus 1
-1