# \#composition

**URL:** https://discourse.julialang.org/tag/composition/889.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Enable all functions to work on element of new type](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210)

<div class="topic-metadata">

**Author:** [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Replies:** 2\
**Last updated:** [August 25, 2023, 11:09pm UTC](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210 "2023-08-25T23:09:54Z")

</div>

If I make a new struct that contains a certain type (a DataFrame in below example) like: struct StructContainingDataFrame df::DataFrame something\_else::Any end Is it then possible to make this work with all fun…

---

## [Efficient way to chain a series of \`diff\` calls](https://discourse.julialang.org/t/efficient-way-to-chain-a-series-of-diff-calls/84275)

<div class="topic-metadata">

**Author:** [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Replies:** 11\
**Last updated:** [July 16, 2022, 12:46pm UTC](https://discourse.julialang.org/t/efficient-way-to-chain-a-series-of-diff-calls/84275 "2022-07-16T12:46:26Z")

</div>

Hi, I would like to call the diff function in base a few times in a row to compute n-th differenced data. Of course, I could import Base.diff and write down an extended version of the function with an ad-hoc for-loop to…

---

## [Julia: function composition: how to correctly split arguments?](https://discourse.julialang.org/t/julia-function-composition-how-to-correctly-split-arguments/61433)

<div class="topic-metadata">

**Author:** [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Replies:** 4\
**Last updated:** [May 19, 2021, 8:00pm UTC](https://discourse.julialang.org/t/julia-function-composition-how-to-correctly-split-arguments/61433 "2021-05-19T20:00:15Z")

</div>

How to define functions/functors and split arguments? I have a struct of fixed parameters, P, a mutable struct of variables, V, and three constructors for methods F, G, and H, where H is the composition of F and G. The …

---

## [Function Composition vs Piping: Is there a performance difference?](https://discourse.julialang.org/t/function-composition-vs-piping-is-there-a-performance-difference/50589)

<div class="topic-metadata">

**Author:** [@Obtuya7](https://discourse.julialang.org/u/Obtuya7)\
**Replies:** 4\
**Last updated:** [November 22, 2020, 9:11pm UTC](https://discourse.julialang.org/t/function-composition-vs-piping-is-there-a-performance-difference/50589 "2020-11-22T21:11:04Z")

</div>

I noticed cases where the pipe operator (e.g. |\> ) is used over function composition (e.g. f(g(x))). I see composition used throughout the base code; so I assume that it’s the preferred convention. Are there any underly…

---

## [Broadcasting and function composition (circ)](https://discourse.julialang.org/t/broadcasting-and-function-composition-circ/46748)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 10\
**Last updated:** [September 18, 2020, 5:13pm UTC](https://discourse.julialang.org/t/broadcasting-and-function-composition-circ/46748 "2020-09-18T17:13:28Z")

</div>

How does one easily compose and broadcast? For example, x = randn(100,10) mapslices(cumprod ∘ exp, x; dims=1) fails because we need to broadcast exp. One workaround is to do the following x = randn(100,10) expdot(v)…

---

## [Function Composition and Piping](https://discourse.julialang.org/t/function-composition-and-piping/46472)

<div class="topic-metadata">

**Author:** [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Replies:** 2\
**Last updated:** [September 11, 2020, 6:48pm UTC](https://discourse.julialang.org/t/function-composition-and-piping/46472 "2020-09-11T18:48:39Z")

</div>

The following are equivalent based on the docs. Is there a Julian preference or functional reason to choose one over another, or is it just a matter of personal taste? Nesting: g(f(x)) Composition: (g ∘ f)(x) Piping: x…

---

## [Playing with function composition, is there a name for what I'm doing?](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533)

<div class="topic-metadata">

**Author:** [@klaff](https://discourse.julialang.org/u/klaff)\
**Replies:** 2\
**Last updated:** [June 16, 2020, 5:06pm UTC](https://discourse.julialang.org/t/playing-with-function-composition-is-there-a-name-for-what-im-doing/41533 "2020-06-16T17:06:34Z")

</div>

For AC analysis of circuits the following is handy: 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/…

---

## [Composition of functions and method dispatch](https://discourse.julialang.org/t/composition-of-functions-and-method-dispatch/35189)

<div class="topic-metadata">

**Author:** [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Replies:** 6\
**Last updated:** [February 26, 2020, 8:08pm UTC](https://discourse.julialang.org/t/composition-of-functions-and-method-dispatch/35189 "2020-02-26T20:08:53Z")

</div>

I have a number of functions like so gfun(m::Type1,t) gfun(m::Type2,t) gfun(m::Type3,x,t) In every case, I would like to define a different function, call it hfun, that takes the same arguments and just composes a sim…

---

## [Square root array using composition function](https://discourse.julialang.org/t/square-root-array-using-composition-function/17014)

<div class="topic-metadata">

**Author:** [@dribeiro142](https://discourse.julialang.org/u/dribeiro142)\
**Replies:** 7\
**Last updated:** [October 31, 2018, 10:08pm UTC](https://discourse.julialang.org/t/square-root-array-using-composition-function/17014 "2018-10-31T22:08:36Z")

</div>

I want to make this function: sum(sqrt.(rand(20))) using function composition, I tried this forms, but none works. (sum ∘ sqrt.)(rand(10)) (sum ∘ sqrt)(rand(10)) (sum .∘ sqrt)(rand(10)) (sum ∘ sqrt)(.rand(10)) How…
