Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contains #718

Merged
merged 3 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Compat"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.14.0"
version = "3.15.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ changes in `julia`.

## Supported features

* `contains(haystack, needle)` and its one argument partially applied form `contains(haystack)` have been added, it acts like `occursin(needle, haystack)` ([#35132]). (since Compat 3.15)

* `Compat.Iterators.map` is added. It provides another syntax `Iterators.map(f, iterators...)`
for writing `(f(args...) for args in zip(iterators...))`, i.e. a lazy `map` ([#34352]).
(since Compat 3.14)
Expand Down Expand Up @@ -192,3 +194,4 @@ Note that you should specify the correct minimum version for `Compat` in the
[#30915]: https://github.com/JuliaLang/julia/pull/30915
[#33437]: https://github.com/JuliaLang/julia/pull/33437
[#34352]: https://github.com/JuliaLang/julia/pull/34352
[#35132]: https://github.com/JuliaLang/julia/pull/35132
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ if VERSION < v"1.2.0-DEV.257" # e7e726b3df1991e1306ef0c566d363c0a83b2dea
Base.:(<)(x) = Base.Fix2(<, x)
end

# https://github.com/JuliaLang/julia/pull/35132
if VERSION < v"1.5.0-DEV.639" # cc6e121386758dff6ba7911770e48dfd59520199
export contains
contains(haystack::AbstractString, needle) = occursin(needle, haystack)
nickrobinson251 marked this conversation as resolved.
Show resolved Hide resolved
contains(needle) = Base.Fix2(contains, needle)
end

include("iterators.jl")
include("deprecated.jl")

Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ end
@test lt5(4) && !lt5(5)
end

@testset "contains" begin
@test contains("foo", "o")
@test contains("o")("foo")
end

include("iterators.jl")

nothing