diff --git a/README.md b/README.md index 82d534b98..7ee2becce 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,10 @@ Currently, the `@compat` macro supports the following syntaxes: * `indmin` and `indmax` are now `argmin` and `argmax`, respectively ([#25654]). +* `Compat.indexin` accepts any iterable as first argument, returns `nothing` (rather than `0`) + for entries with no match and gives the index of the first (rather than the last) match + ([#25662], [#25998]). + * `isabstract` and `isleaftype` are now `isabstracttype` and `isconcretetype`, respectively ([#23666], [#25496]). @@ -576,6 +580,7 @@ includes this fix. Find the minimum version from there. [#25646]: https://github.com/JuliaLang/julia/issues/25646 [#25647]: https://github.com/JuliaLang/julia/issues/25647 [#25654]: https://github.com/JuliaLang/julia/issues/25654 +[#25662]: https://github.com/JuliaLang/julia/issues/25662 [#25705]: https://github.com/JuliaLang/julia/issues/25705 [#25706]: https://github.com/JuliaLang/julia/issues/25706 [#25738]: https://github.com/JuliaLang/julia/issues/25738 @@ -585,6 +590,7 @@ includes this fix. Find the minimum version from there. [#25896]: https://github.com/JuliaLang/julia/issues/25896 [#25959]: https://github.com/JuliaLang/julia/issues/25959 [#25990]: https://github.com/JuliaLang/julia/issues/25990 +[#25998]: https://github.com/JuliaLang/julia/issues/25998 [#26069]: https://github.com/JuliaLang/julia/issues/26069 [#26089]: https://github.com/JuliaLang/julia/issues/26089 [#26149]: https://github.com/JuliaLang/julia/issues/26149 diff --git a/src/Compat.jl b/src/Compat.jl index 08f5f221f..9df1a2054 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1666,6 +1666,21 @@ end Base.mv(src, dst; remove_destination = force) end +if VERSION < v"0.7.0-DEV.3972" + function indexin(a, b::AbstractArray) + inds = keys(b) + bdict = Dict{eltype(b),eltype(inds)}() + for (val, ind) in zip(b, inds) + get!(bdict, val, ind) + end + return Union{eltype(inds), Nothing}[ + get(bdict, i, nothing) for i in a + ] + end +else + const indexin = Base.indexin +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 35809e131..0d43586fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1488,4 +1488,7 @@ mktempdir(@__DIR__) do dir @test readdir(dir) == ["dest.jl"] end +# 0.7.0-DEV.3972 +@test Compat.indexin([1, 2], [1, 0, 1]) == [1, nothing] + nothing