From 4c659ff7e85ef03cc292a1b7113e482921f61fea Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Wed, 4 Mar 2026 14:25:38 +0100 Subject: [PATCH 1/4] simplify `firstrest` using `Iterators.peel` `Iterators.peel` is supported on all Julia versions supported by IterTools. In fact, it was already present with Julia v0.7. --- src/IterTools.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/IterTools.jl b/src/IterTools.jl index 8499fa6..3aeeaf9 100644 --- a/src/IterTools.jl +++ b/src/IterTools.jl @@ -128,11 +128,9 @@ julia> collect(r) ``` """ function firstrest(xs) - t = iterate(xs) + t = Iterators.peel(xs) t === nothing && throw(ArgumentError("collection must be non-empty")) - f, s = t - r = Iterators.rest(xs, s) - return f, r + return t end # Iterate through the first n elements, throwing an exception if From 158dcc6f33d43c4508b27f21fb39d17acd6ec7dd Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sun, 8 Mar 2026 11:31:56 +0100 Subject: [PATCH 2/4] deprecate `firstrest` --- src/IterTools.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/IterTools.jl b/src/IterTools.jl index 3aeeaf9..5dab9ad 100644 --- a/src/IterTools.jl +++ b/src/IterTools.jl @@ -128,6 +128,7 @@ julia> collect(r) ``` """ function firstrest(xs) + Base.depwarn("`firstrest` is deprecated in favor of `Iterators.peel`", :firstrest) t = Iterators.peel(xs) t === nothing && throw(ArgumentError("collection must be non-empty")) return t From d96f4a18c1b90608e948ab81659d91a2892f2646 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Fri, 27 Mar 2026 13:52:11 +0100 Subject: [PATCH 3/4] just make it an alias --- src/IterTools.jl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/IterTools.jl b/src/IterTools.jl index 5dab9ad..c7d92a0 100644 --- a/src/IterTools.jl +++ b/src/IterTools.jl @@ -113,7 +113,7 @@ end Return the first element and an iterator of the rest as a tuple. -See also: `Base.Iterators.peel`. +Alias for `Base.Iterators.peel`. ```jldoctest julia> f, r = firstrest(1:3); @@ -127,12 +127,7 @@ julia> collect(r) 3 ``` """ -function firstrest(xs) - Base.depwarn("`firstrest` is deprecated in favor of `Iterators.peel`", :firstrest) - t = Iterators.peel(xs) - t === nothing && throw(ArgumentError("collection must be non-empty")) - return t -end +const firstrest = Iterators.peel # Iterate through the first n elements, throwing an exception if # fewer than n items ar encountered. From 1c61fb9852431f2576eafa0b4cc93fc01bd20d0d Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Fri, 27 Mar 2026 13:58:38 +0100 Subject: [PATCH 4/4] update test --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2b375dc..b802f1d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,7 +36,7 @@ include("testing_macros.jl") ] @testset "$xs" for (xs, s) in test_empty_cases - @test_throws ArgumentError firstrest(xs) + @test nothing === firstrest(xs) end end