@@ -1720,18 +1720,7 @@ julia> findnext(A, CartesianIndex(1, 1))
1720
1720
CartesianIndex(2, 1)
1721
1721
```
1722
1722
"""
1723
- function findnext (A, start)
1724
- l = last (keys (A))
1725
- i = oftype (l, start)
1726
- i > l && return nothing
1727
- while true
1728
- A[i] && return i
1729
- i == l && break
1730
- # nextind(A, l) can throw/overflow
1731
- i = nextind (A, i)
1732
- end
1733
- return nothing
1734
- end
1723
+ findnext (A, start) = findnext (identity, A, start)
1735
1724
1736
1725
"""
1737
1726
findfirst(A)
@@ -1766,14 +1755,7 @@ julia> findfirst(A)
1766
1755
CartesianIndex(2, 1)
1767
1756
```
1768
1757
"""
1769
- function findfirst (A)
1770
- for (i, a) in pairs (A)
1771
- if a
1772
- return i
1773
- end
1774
- end
1775
- return nothing
1776
- end
1758
+ findfirst (A) = findfirst (identity, A)
1777
1759
1778
1760
# Needed for bootstrap, and allows defining only an optimized findnext method
1779
1761
findfirst (A:: Union{AbstractArray, AbstractString} ) = findnext (A, first (keys (A)))
@@ -1907,18 +1889,7 @@ julia> findprev(A, CartesianIndex(2, 1))
1907
1889
CartesianIndex(2, 1)
1908
1890
```
1909
1891
"""
1910
- function findprev (A, start)
1911
- f = first (keys (A))
1912
- i = oftype (f, start)
1913
- i < f && return nothing
1914
- while true
1915
- A[i] && return i
1916
- i == f && break
1917
- # prevind(A, f) can throw/underflow
1918
- i = prevind (A, i)
1919
- end
1920
- return nothing
1921
- end
1892
+ findprev (A, start) = findprev (identity, A, start)
1922
1893
1923
1894
"""
1924
1895
findlast(A)
@@ -1954,14 +1925,7 @@ julia> findlast(A)
1954
1925
CartesianIndex(2, 1)
1955
1926
```
1956
1927
"""
1957
- function findlast (A)
1958
- for (i, a) in Iterators. reverse (pairs (A))
1959
- if a
1960
- return i
1961
- end
1962
- end
1963
- return nothing
1964
- end
1928
+ findlast (A) = findlast (identity, A)
1965
1929
1966
1930
# Needed for bootstrap, and allows defining only an optimized findprev method
1967
1931
findlast (A:: Union{AbstractArray, AbstractString} ) = findprev (A, last (keys (A)))
@@ -2145,9 +2109,8 @@ julia> findall(falses(3))
2145
2109
Int64[]
2146
2110
```
2147
2111
"""
2148
- function findall (A)
2149
- collect (first (p) for p in pairs (A) if last (p))
2150
- end
2112
+ findall (A) = findall (identity, A)
2113
+
2151
2114
# Allocating result upfront is faster (possible only when collection can be iterated twice)
2152
2115
function findall (A:: AbstractArray{Bool} )
2153
2116
n = count (A)
0 commit comments