Skip to content

Commit 7481eb8

Browse files
Add curried endswith, startswith (#719)
1 parent d4aecbb commit 7481eb8

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ changes in `julia`.
5757

5858
* `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)
5959

60+
* `startswith(x)` and `endswith(x)`, returning partially-applied versions of the functions, similar to existing methods like `isequal(x)` ([#35052]). (since Compat 3.15)
61+
6062
* `Compat.Iterators.map` is added. It provides another syntax `Iterators.map(f, iterators...)`
6163
for writing `(f(args...) for args in zip(iterators...))`, i.e. a lazy `map` ([#34352]).
6264
(since Compat 3.14)
@@ -131,7 +133,6 @@ changes in `julia`.
131133

132134
* `range` supporting `stop` as positional argument ([#28708]). (since Compat 1.3.0)
133135

134-
135136
## Developer tips
136137

137138
One of the most important rules for `Compat.jl` is to avoid breaking user code
@@ -195,3 +196,4 @@ Note that you should specify the correct minimum version for `Compat` in the
195196
[#33437]: https://github.com/JuliaLang/julia/pull/33437
196197
[#34352]: https://github.com/JuliaLang/julia/pull/34352
197198
[#35132]: https://github.com/JuliaLang/julia/pull/35132
199+
[#35052]: https://github.com/JuliaLang/julia/pull/35052

src/Compat.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,12 @@ if VERSION < v"1.5.0-DEV.639" # cc6e121386758dff6ba7911770e48dfd59520199
601601
contains(needle) = Base.Fix2(contains, needle)
602602
end
603603

604+
# https://github.com/JuliaLang/julia/pull/35052
605+
if VERSION < v"1.5.0-DEV.438" # 0a43c0f1d21ce9c647c49111d93927369cd20f85
606+
Base.endswith(s) = Base.Fix2(endswith, s)
607+
Base.startswith(s) = Base.Fix2(startswith, s)
608+
end
609+
604610
include("iterators.jl")
605611
include("deprecated.jl")
606612

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ end
550550
@test contains("o")("foo")
551551
end
552552

553+
# https://github.com/JuliaLang/julia/pull/35052
554+
@testset "curried startswith/endswith" begin
555+
@test startswith("a")("abcd")
556+
@test endswith("d")("abcd")
557+
end
558+
553559
include("iterators.jl")
554560

555561
nothing

0 commit comments

Comments
 (0)