Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/IterTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading