# any(f::Function, a::AbstractArray; dims)

**URL:** https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607
**Category:** General Usage
**Created:** [July 6, 2020, 12:57pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607 "2020-07-06T12:57:52Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [July 6, 2020, 12:57pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/1 "2020-07-06T12:57:52Z")

</div>

is defined (reducedim.jl:729, Julia 1.5.0-rc1.0), but _not documented_.

Also, its behaviour is slightly different from `any(a;dims)`, For instance,  
`any([1 2].>0,dims=2)` gives a BitArray, while `any(i->i>0,[1 2],dims=2)` gives an array of Bools.

I would prefer to use the `any(f, a; dims)` method to avoid allocations (when `a` is large), but I wonder whether I can rely on it?

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [July 6, 2020, 2:11pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/3 "2020-07-06T14:11:34Z")

</div>

> [@Tamas\_Papp](#):
>
> It could either be documented, or deprecated in favor of a form that deals with the callable ambiguity

I imagine you mean that in the `any(f, array)` signature `f` is required to be a function, but I couldn’t figure out why that’s needed. What would `any(f, array::AbstractArray)` be ambiguous with? Maybe that’s just a leftover from when `dims` was a positional argument.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 6, 2020, 2:38pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/4 "2020-07-06T14:38:17Z")

</div>

Sorry, I was thinking of something else; please disregard.

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [July 6, 2020, 3:19pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/5 "2020-07-06T15:19:28Z")

</div>

Ah, no problem!

It is a bit hard to keep in mind which functions have a method where the first element is any callable object or just `::Function`. I would definitely prefer to have good syntax for a lazy broadcasted object and just do `any(for f.(x))` (as in [this PR](https://github.com/JuliaLang/julia/pull/31553)) or whichever other syntax gets chosen.

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [July 6, 2020, 3:36pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/6 "2020-07-06T15:36:40Z")

</div>

Do you recommend to stay away from `any(f,a;dims)` for now?

---

<div class="post-metadata">

### Author: ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)
#### Post date: [July 6, 2020, 3:48pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/7 "2020-07-06T15:48:33Z")

</div>

I don’t have any special insight, but I think it should be fine: IMO it would be breaking to change the behavior of an exported function. Just in case, you could open an issue or PR to mention that it needs docs.

---

<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: [July 6, 2020, 5:43pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/8 "2020-07-06T17:43:22Z")

</div>

It would be breaking to change the behavior of the _public API_, and I am not sure if the public API is defined by the body of the exported functions or by the body of the documented functions. I would advise opening a PR asking for documentation, and then get the answer if it is intended to be part of the public API or not.

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [July 7, 2020, 9:10am UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/9 "2020-07-07T09:10:17Z")

</div>

submitted [https://github.com/JuliaLang/julia/pull/36559](https://github.com/JuliaLang/julia/pull/36559)

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [July 16, 2020, 3:12pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/10 "2020-07-16T15:12:47Z")

</div>

@piever and @Henrique_Becker: the PR is now merged

---

<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: [July 16, 2020, 3:18pm UTC](https://discourse.julialang.org/t/any-f-function-a-abstractarray-dims/42607/11 "2020-07-16T15:18:10Z")

</div>

Oh, good news. Thanks for pinging back. Good contribution.
