# Add \`find\` method to look for a specific element (paralleling \`findfirst\`, etc.)

**URL:** <https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [August 15, 2017, 8:47pm UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397 "2017-08-15T20:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tparker](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tparker](https://discourse.julialang.org/u/tparker)\
**Post date:** [August 15, 2017, 8:47pm UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397/1 "2017-08-15T20:47:36Z")

</div>

Probably the single most common use of the variants of the `find` method is to search for a specific element in an array. The `Base` methods `findfirst`, `findlast`, `findnext`, and `findprev` all conveniently implement this functionality by having methods of the form `findfirst(A, v)` which check the elements of the array `A` for equality with the specific element `v`. But `find` does not; in order to search an array for the indices of _all_ the appearances of an element `v` in an array `A`, we need to use the more cumbersome predicate-specification version `find(x -> x == v, A)`. Should we add a method `find(A, v)`, in order to parallel the other variant methods?

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [August 15, 2017, 10:21pm UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397/2 "2017-08-15T22:21:41Z")

</div>

`find(A .== v)` is the same and less cumbersome

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 16, 2017, 12:16am UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397/3 "2017-08-16T00:16:38Z")

</div>

Except it could be less performant when `A` is large and `A .== v` is sparse.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [August 16, 2017, 6:05am UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397/4 "2017-08-16T06:05:21Z")

</div>

That’s right.  
But what would be nice here is “broadcast fusing”, making the above as performant as the typical evaluation.  
In any case, for better performance, there is also:

```julia
myfind(A,v) = collect(i for (i,e) in enumerate(a) if e==v) 

```

or maybe the same without the `collect` as sometimes an iterator is what you need.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [August 16, 2017, 7:34am UTC](https://discourse.julialang.org/t/add-find-method-to-look-for-a-specific-element-paralleling-findfirst-etc/5397/5 "2017-08-16T07:34:29Z")

</div>

I have an old [PR](https://github.com/JuliaLang/julia/pull/9340) implementing this, which unfortunatly didn’t get much support. I will rebase it though.
