# Composing a function with keyword arguments

**URL:** https://discourse.julialang.org/t/composing-a-function-with-keyword-arguments/66677
**Category:** General Usage
**Created:** [August 19, 2021, 1:57pm UTC](https://discourse.julialang.org/t/composing-a-function-with-keyword-arguments/66677 "2021-08-19T13:57:23Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [August 19, 2021, 3:46pm UTC](https://discourse.julialang.org/t/composing-a-function-with-keyword-arguments/66677/5 "2021-08-19T15:46:08Z")

</div>

You can achieve that with a functor:

> [@In Julia, how to create a function that saves its own internal state?](https://discourse.julialang.org/t/in-julia-how-to-create-a-function-that-saves-its-own-internal-state/58457/6):
>
> Or a functor? struct F state end (o::F)(x) = o.state + x f = F(1) f(2) 3 more specifically: julia\> Base.@kwdef mutable struct F state = nothing end F julia\> function (o::F)() if o.state == nothing o.state = 1 else o.state += 1 end end julia\> f = F() F(nothing) julia\> f() 1 julia\> f() 2 julia\> f() 3 julia\> f.state # now this is part of the language, because f is an instance of F 3

Though it is probably good to be sure that’s is the best strategy for what you really want to do.

---

_[View the full topic](https://discourse.julialang.org/t/composing-a-function-with-keyword-arguments/66677)._
