From 81bc0884b0590e42f96e413974fc0218681787d0 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Wed, 4 Mar 2026 14:25:38 +0100 Subject: [PATCH 1/2] 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 b5e62f6..543ada2 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 482313a172f1635395583e986fc5b3fe2855367c Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Sun, 8 Mar 2026 11:31:56 +0100 Subject: [PATCH 2/2] deprecate `firstrest` --- src/IterTools.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/IterTools.jl b/src/IterTools.jl index 543ada2..71b1645 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