Skip to content

Commit d4aecbb

Browse files
Add contains (#718)
1 parent 954e4d0 commit d4aecbb

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Compat"
22
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
3-
version = "3.14.0"
3+
version = "3.15.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ changes in `julia`.
5555

5656
## Supported features
5757

58+
* `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)
59+
5860
* `Compat.Iterators.map` is added. It provides another syntax `Iterators.map(f, iterators...)`
5961
for writing `(f(args...) for args in zip(iterators...))`, i.e. a lazy `map` ([#34352]).
6062
(since Compat 3.14)
@@ -192,3 +194,4 @@ Note that you should specify the correct minimum version for `Compat` in the
192194
[#30915]: https://github.com/JuliaLang/julia/pull/30915
193195
[#33437]: https://github.com/JuliaLang/julia/pull/33437
194196
[#34352]: https://github.com/JuliaLang/julia/pull/34352
197+
[#35132]: https://github.com/JuliaLang/julia/pull/35132

src/Compat.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,13 @@ if VERSION < v"1.2.0-DEV.257" # e7e726b3df1991e1306ef0c566d363c0a83b2dea
594594
Base.:(<)(x) = Base.Fix2(<, x)
595595
end
596596

597+
# https://github.com/JuliaLang/julia/pull/35132
598+
if VERSION < v"1.5.0-DEV.639" # cc6e121386758dff6ba7911770e48dfd59520199
599+
export contains
600+
contains(haystack::AbstractString, needle) = occursin(needle, haystack)
601+
contains(needle) = Base.Fix2(contains, needle)
602+
end
603+
597604
include("iterators.jl")
598605
include("deprecated.jl")
599606

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ end
545545
@test lt5(4) && !lt5(5)
546546
end
547547

548+
@testset "contains" begin
549+
@test contains("foo", "o")
550+
@test contains("o")("foo")
551+
end
552+
548553
include("iterators.jl")
549554

550555
nothing

0 commit comments

Comments
 (0)