In 0.6 findfirst(::Function, ::A) would return the index of the first element that caused the predicate function to return true, and 0 if it is not present. Now it returns ‘nothing’… of type ‘Nothing’, so will this cause issue with type inference and compilation of efficient code, if you don’t know you will be dealing with an Int or a Nothing?
Not sure, but you can replicate part of findfirst’s behaviour with map() fairly easily. It will run over the whole array though, so it would be more like a findall function.
You’d probably have to check the output for zeros/nothings at some point though, except where the value is certain to be in the set?
Added- worth checking to see if A[nothing] throws an error or is graceful
Yes, it’s not type stable, but the language has been enhanced (and is in the process of being further enhanced) to allow small unions to be handled efficiently, so there’s no performance penalty anymore.
Brilliant! Quick follow-up: are there also plans to stop highlighting small unions in red in
@code_warntype? Example below for convenience.
A = [1 4; 2 2] @code_warntype findfirst(iseven, A)
They’re highlighted in yellow on master.