# Compose a monadic function

**URL:** <https://forum.kx.com/t/compose-a-monadic-function/11626>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [October 17, 2017, 8:10pm UTC](https://forum.kx.com/t/compose-a-monadic-function/11626 "2017-10-17T20:10:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trentkg](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@trentkg](https://forum.kx.com/u/trentkg)\
**Post date:** [October 17, 2017, 8:10pm UTC](https://forum.kx.com/t/compose-a-monadic-function/11626/1 "2017-10-17T20:10:00Z")

</div>

Say I have a simple function:&nbsp;

`f: {[x] 10?x};`

Is there a way to compose this function, and get a new function that takes no arguments? I can’t see a way to do this without either

1. calling the function&nbsp;

`g: f[10]; /Not what we want`

1. using globals

`global: 10;g:{ 10?global};`

1. Using a dummy argument

`f: {[x] 10?x};g: {[x;y;z] @[x;y] }[f;10;];g[`dummy]`

---

<div class="post-metadata">

**Author:** ![jwbuitenhuis](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jwbuitenhuis](https://forum.kx.com/u/jwbuitenhuis)\
**Post date:** [October 17, 2017, 8:40pm UTC](https://forum.kx.com/t/compose-a-monadic-function/11626/2 "2017-10-17T20:40:00Z")

</div>

Here’s one approach - generate the function from a string of q.

q)g:{value “{10?”,(string x),“}”}

q)f:g[10]

q)f

5 4 2 5 8 7 9 9 7 7

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [October 17, 2017, 8:49pm UTC](https://forum.kx.com/t/compose-a-monadic-function/11626/3 "2017-10-17T20:49:00Z")

</div>

q)f:{10?x}

q)g:('[f;{100}])

q)g

12 10 1 90 73 90 43 90 84 63

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [October 17, 2017, 8:52pm UTC](https://forum.kx.com/t/compose-a-monadic-function/11626/4 "2017-10-17T20:52:00Z")

</div>

or more simply

q)g:{f 10}

not entirely sure what you want.
