@@ -1495,7 +1495,7 @@ cat(n::Integer, x::Integer...) = reshape([x...], (ntuple(x->1, n-1)..., length(x
14951495"""
14961496 findnext(A, i::Integer)
14971497
1498- Find the next linear index >= `i` of a `true` element of `A`, or `0 ` if not found.
1498+ Find the next linear index >= `i` of a `true` element of `A`, or `nothing ` if not found.
14991499
15001500# Examples
15011501```jldoctest
@@ -1508,7 +1508,6 @@ julia> findnext(A, 1)
150815082
15091509
15101510julia> findnext(A, 3)
1511- 0
15121511```
15131512"""
15141513function findnext (A, start:: Integer )
@@ -1526,14 +1525,14 @@ function findnext(A, start::Integer)
15261525 end
15271526 i = nextind (A, i)
15281527 end
1529- return 0
1528+ return nothing
15301529end
15311530
15321531"""
15331532 findfirst(A)
15341533
15351534Return the linear index of the first `true` value in `A`.
1536- Return `0 ` if no such value is found.
1535+ Return `nothing ` if no such value is found.
15371536To search for other kinds of values, pass a predicate as the first argument.
15381537
15391538# Examples
@@ -1546,16 +1545,17 @@ julia> A = [false false; true false]
15461545julia> findfirst(A)
154715462
15481547
1549- julia> findfirst(falses(3))
1550- 0
1548+ julia> findfirst(falses(3)) == nothing
1549+ true
15511550```
15521551"""
15531552findfirst (A) = findnext (A, 1 )
15541553
15551554"""
15561555 findnext(predicate::Function, A, i::Integer)
15571556
1558- Find the next linear index >= `i` of an element of `A` for which `predicate` returns `true`, or `0` if not found.
1557+ Find the next linear index >= `i` of an element of `A` for which `predicate` returns `true`,
1558+ or `nothing` if not found.
15591559
15601560# Examples
15611561```jldoctest
@@ -1567,8 +1567,8 @@ julia> A = [1 4; 2 2]
15671567julia> findnext(isodd, A, 1)
156815681
15691569
1570- julia> findnext(isodd, A, 2)
1571- 0
1570+ julia> findnext(isodd, A, 2) == nothing
1571+ true
15721572```
15731573"""
15741574function findnext (testf:: Function , A, start:: Integer )
@@ -1580,14 +1580,14 @@ function findnext(testf::Function, A, start::Integer)
15801580 end
15811581 i = nextind (A, i)
15821582 end
1583- return 0
1583+ return nothing
15841584end
15851585
15861586"""
15871587 findfirst(predicate::Function, A)
15881588
15891589Return the linear index of the first element of `A` for which `predicate` returns `true`.
1590- Return `0 ` if there is no such element.
1590+ Return `nothing ` if there is no such element.
15911591
15921592# Examples
15931593```jldoctest
@@ -1599,8 +1599,8 @@ julia> A = [1 4; 2 2]
15991599julia> findfirst(iseven, A)
160016002
16011601
1602- julia> findfirst(x -> x>10, A)
1603- 0
1602+ julia> findfirst(x -> x>10, A) == nothing
1603+ true
16041604
16051605julia> findfirst(equalto(4), A)
160616063
@@ -1611,7 +1611,7 @@ findfirst(testf::Function, A) = findnext(testf, A, 1)
16111611"""
16121612 findprev(A, i::Integer)
16131613
1614- Find the previous linear index <= `i` of a `true` element of `A`, or `0 ` if not found.
1614+ Find the previous linear index <= `i` of a `true` element of `A`, or `nothing ` if not found.
16151615
16161616# Examples
16171617```jldoctest
@@ -1623,8 +1623,8 @@ julia> A = [false false; true true]
16231623julia> findprev(A,2)
162416242
16251625
1626- julia> findprev(A,1)
1627- 0
1626+ julia> findprev(A,1) == nothing
1627+ true
16281628```
16291629"""
16301630function findprev (A, start:: Integer )
@@ -1639,14 +1639,14 @@ function findprev(A, start::Integer)
16391639 a != 0 && return i
16401640 i = prevind (A, i)
16411641 end
1642- return 0
1642+ return nothing
16431643end
16441644
16451645"""
16461646 findlast(A)
16471647
16481648Return the linear index of the last `true` value in `A`.
1649- Return `0 ` if there is no `true` value in `A`.
1649+ Return `nothing ` if there is no `true` value in `A`.
16501650
16511651# Examples
16521652```jldoctest
@@ -1660,8 +1660,8 @@ julia> findlast(A)
16601660
16611661julia> A = falses(2,2);
16621662
1663- julia> findlast(A)
1664- 0
1663+ julia> findlast(A) == nothing
1664+ true
16651665```
16661666"""
16671667findlast (A) = findprev (A, endof (A))
@@ -1670,7 +1670,7 @@ findlast(A) = findprev(A, endof(A))
16701670 findprev(predicate::Function, A, i::Integer)
16711671
16721672Find the previous linear index <= `i` of an element of `A` for which `predicate` returns `true`, or
1673- `0 ` if not found.
1673+ `nothing ` if not found.
16741674
16751675# Examples
16761676```jldoctest
@@ -1679,8 +1679,8 @@ julia> A = [4 6; 1 2]
16791679 4 6
16801680 1 2
16811681
1682- julia> findprev(isodd, A, 1)
1683- 0
1682+ julia> findprev(isodd, A, 1) == nothing
1683+ true
16841684
16851685julia> findprev(isodd, A, 3)
168616862
@@ -1692,14 +1692,14 @@ function findprev(testf::Function, A, start::Integer)
16921692 testf (A[i]) && return i
16931693 i = prevind (A, i)
16941694 end
1695- return 0
1695+ return nothing
16961696end
16971697
16981698"""
16991699 findlast(predicate::Function, A)
17001700
17011701Return the linear index of the last element of `A` for which `predicate` returns `true`.
1702- Return `0 ` if there is no such element.
1702+ Return `nothing ` if there is no such element.
17031703
17041704# Examples
17051705```jldoctest
@@ -1711,12 +1711,14 @@ julia> A = [1 2; 3 4]
17111711julia> findlast(isodd, A)
171217122
17131713
1714- julia> findlast(x -> x > 5, A)
1715- 0
1714+ julia> findlast(x -> x > 5, A) == nothing
1715+ true
17161716```
17171717"""
17181718findlast (testf:: Function , A) = findprev (testf, A, endof (A))
17191719
1720+ nothing_sentinel (i) = i == 0 ? nothing : i
1721+
17201722"""
17211723 find(f::Function, A)
17221724
0 commit comments