# The new output of findfirst is dangerous

**URL:** <https://discourse.julialang.org/t/the-new-output-of-findfirst-is-dangerous/9131>\
**Category:** General Usage\
**Created:** [February 17, 2018, 5:03pm UTC](https://discourse.julialang.org/t/the-new-output-of-findfirst-is-dangerous/9131 "2018-02-17T17:03:21Z")\
**Posts on this page:** 1\
**Showing post:** 12

<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:** [February 17, 2018, 7:49pm UTC](https://discourse.julialang.org/t/the-new-output-of-findfirst-is-dangerous/9131/12 "2018-02-17T19:49:02Z")

</div>

I don’t know much about the `findfirst` usecase for strings as I very rarely do string processing but concerning the element in a collection method, I find the new behavior much better. Returning `0` is not very principled and could lead to issues (for example, if I’m using OffsetArrays, did I find `0` or did I not find anything at all?).

Returning `nothing` has several advantages:

- There can be no confusion as to whether a match was found or not
- One can dispatch on the returned type to decide what to do next
- If desired, it’s easy to replace it with some other value with `coalesce`:

```julia
coalesce(findfirst(equalto(el), v), 0)

```

To simplify checking for nothingness, I wonder whether it’d be helpful to have `isnothing` (analogous to `ismissing`), but it’s also true that `x isa Nothing` isn’t much longer.

---

_[View the full topic](https://discourse.julialang.org/t/the-new-output-of-findfirst-is-dangerous/9131)._
