# There is a \`f(g) = function(args...) broadcast(g, args...) end\` in \`Base\`?

**URL:** <https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841>\
**Category:** New to Julia\
**Created:** [June 5, 2020, 11:50pm UTC](https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841 "2020-06-05T23:50:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 5, 2020, 11:50pm UTC](https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841/1 "2020-06-05T23:50:47Z")

</div>

I know I can define a function like:

```julia
wrap_in_broadcast(f) = function (args...)
    broadcast(f, args...)
end

```

I defined this function because many times I need to pass a function to another function, or use `∘` over a broadcasted version of simple function (like `sum ∘ ismissing.` but this dot is not valid sintax). As simple as it is to define this function, seems to me that I am missing something, as it seems useful enough to exist in the standard library but I did not found it. What have I missed?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [June 6, 2020, 1:10am UTC](https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841/2 "2020-06-06T01:10:43Z")

</div>

Do you have other examples of when you’d use `wrap_in_broadcast`? For your given example, `count(ismissing, v)` works well, or `sum(skipmissing(v))` if you’re trying to sum the non-missing values.

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [June 6, 2020, 2:16am UTC](https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841/3 "2020-06-06T02:16:46Z")

</div>

Do you want [Transducers.jl](https://github.com/JuliaFolds/Transducers.jl) ?

```julia
julia> using Transducers
julia> skipmissing_sum(iter) = reduce(+, Filter(!ismissing), iter)
julia> skipmissing_sum([1, 2, missing, 3, 5]
11

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 6, 2020, 2:47am UTC](https://discourse.julialang.org/t/there-is-a-f-g-function-args-broadcast-g-args-end-in-base/40841/4 "2020-06-06T02:47:30Z")

</div>

@stillyslalom Hard to remember examples for memory, as it is a very generic situation. However, it was frequent enough to me to perceive the pattern. It started with me creating a plural version of some function to be able to pass them, after I started to use an anonymous function for the same purpose, and then finally I defined a `wrap_in_broadcast` (after renamed to `broadwrap`). So I would say it is frequent.

@L_Adam I had already heard of Transducers.jl but never really looked into it. Seems something worth learning. It has a [`Broadcasting`](https://juliafolds.github.io/Transducers.jl/stable/manual/#Transducers.Broadcasting) that seems what I want, but inside their framework. Remember me the flow of Haskell code what is a plus to me.
