Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,8 @@ findfirst(testf::Function, A::Union{AbstractArray, AbstractString}) =
findnext(testf, A, first(keys(A)))

function findfirst(p::Union{Fix2{typeof(isequal),T},Fix2{typeof(==),T}}, r::StepRange{T,S}) where {T,S}
first(r) <= p.x <= last(r) || return nothing
isempty(r) && return nothing
minimum(r) <= p.x <= maximum(r) || return nothing
d = convert(S, p.x - first(r))
iszero(d % step(r)) || return nothing
return d ÷ step(r) + 1
Expand Down
1 change: 1 addition & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ end
@test findfirst(==(7), 1:2:10) == 4
@test findfirst(==(10), 1:2:10) == nothing
@test findfirst(==(11), 1:2:10) == nothing
@test findfirst(==(-7), 1:-1:-10) == 9
end
@testset "reverse" begin
@test reverse(reverse(1:10)) == 1:10
Expand Down