# Playing with function composition, is there a name for what I'm doing?

**URL:** <https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533>\
**Category:** Optimization (Mathematical)\
**Tags:** composition\
**Created:** [June 16, 2020, 4:30pm UTC](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533 "2020-06-16T16:30:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [June 16, 2020, 4:30pm UTC](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533/1 "2020-06-16T16:30:07Z")

</div>

For AC analysis of circuits the following is handy:

```julia
using Plots

ZL(L) = f -> im*2π*f*L
ZC(C) = f -> 1/(im*2π*f*C)
ZR(R) = f -> R
series(a,b,c...) = f -> sum([x(f) for x in [[a,b]; [c...]]])
parallel(a,b,c...) = f -> 1/(sum([1/x(f) for x in [[a,b]; [c...]]]))
voltage_divider(top,bottom) = f -> bottom(f)/(top(f)+bottom(f))

# textbook example from p 157 of https://web.stanford.edu/class/archive/engr/engr40m.1178/reader/chapter7.pdf
G = voltage_divider(series(ZR(4.7e3),ZC(47e-9)), parallel(ZC(1e-9),ZR(2.2e3)))
plot([10^x for x in 1.9:0.001:7.1],f->20*log(abs(G(f))),leg=false,xscale=:log10)

```

This lets me write simple expressions for complicated circuit structures and avoid tons of algebra (see the referenced book for an example).

I’m curious if there is a name for this type of manipulation of functions with a common argument.

Thanks.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 16, 2020, 4:39pm UTC](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533/2 "2020-06-16T16:39:28Z")

</div>

I don’t know if there is a more specific term for this than “functional programming”.

By the way, I think it’s neat that you’ve found a functional style that happens to be very similar to the way Mux.jl handles web requests: [Mux.jl/Mux.jl at c3f12af75de425bfc3c7a6fdb400332398be3005 · JuliaWeb/Mux.jl · GitHub](https://github.com/JuliaWeb/Mux.jl/blob/c3f12af75de425bfc3c7a6fdb400332398be3005/src/Mux.jl#L9-L18)

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [June 16, 2020, 5:06pm UTC](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533/3 "2020-06-16T17:06:34Z")

</div>

That’s cool! I asked the question because I couldn’t figure out how to search for the pattern - it’s pretty simple but just a little different arrangement from the basic `f∘g` thing.
