The new output of findfirst is dangerous

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:
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.

2 Likes