diff --git a/src/IterTools.jl b/src/IterTools.jl index 8499fa6..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,13 +127,7 @@ julia> collect(r) 3 ``` """ -function firstrest(xs) - t = iterate(xs) - t === nothing && throw(ArgumentError("collection must be non-empty")) - f, s = t - r = Iterators.rest(xs, s) - return f, r -end +const firstrest = Iterators.peel # Iterate through the first n elements, throwing an exception if # fewer than n items ar encountered. 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