KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Function composition using common argument Re: Function composition using common argument

  • Laura

    Administrator
    October 27, 2022 at 12:00 am
    Q doesnt really offer built-in combinators as liberally as its ancestor language APL does. An elegant way to compose the projections of f1 and f2? You can lose the parens
    q)c: f1[;a] f2[;a]@ 
    q)c 3 
    0n 0.5 0.5 0.3333333 0.25 0.2 0.1666667 0.1428571 0.125 0.1111111
    Of course, if you have to do this often, you can write your own combinator. Call it cr for curry right:
    q)cr:{x[;y]} 
    q)c:('[;])over(f1;f2)cr:a  / Compose over (f1[;a];f2[;a]) 
    q)c 3 
    0n 0.5 0.5 0.3333333 0.25 0.2 0.1666667 0.1428571 0.125 0.1111111
    Compose over a list of functions as many as you need.