Everyone,

I just recently needed to find the index of the n-th occurrence of a
predicate an Array and was a bit surprised that there was not a
convenience function in Base.  Rolling one on your own is simple, but
I somehow expected to find something in Base to get the same
functionality.

    function findocc(testf::Function, A, n)
        i = 0
        for _ in 1:n
            i = findnext(testf, A, i + 1)
            i != 0 || return 0
        end
        return i
    end

Am I perhaps missing something that is already supported in Base? [1]
If not, I may consider yet another small pull request.  But as always
with these small convenience functions I fear that I am missing
something obvious that already supports the same functionality.

    Pontus

[1]: 
http://julia.readthedocs.org/en/latest/stdlib/arrays/?highlight=find#Base.find

Reply via email to