Skip to content

Commit

Permalink
fix: doctests. add doctests for zip_longest too.
Browse files Browse the repository at this point in the history
  • Loading branch information
digital-carver committed Nov 8, 2023
1 parent 403cdca commit 9c6feb3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Documenter, IterTools

DocMeta.setdocmeta!(IterTools, :DocTestSetup, :(using IterTools))
makedocs(
modules = [IterTools],
sitename = "IterTools",
pages = [
"Docs" => "index.md",
],
doctest=false,
doctest=true,
)

deploydocs(
Expand Down
6 changes: 0 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
```@meta
DocTestSetup = quote
using IterTools
end
```

# IterTools

## Installation
Expand Down
31 changes: 25 additions & 6 deletions src/IterTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,12 @@ Input:
```jldoctest
julia> collect(interleaveby(1:2:5, 2:2:6))
6-element Vector{Int64}:
1
2
3
4
5
6
1
2
3
4
5
6
```
If the predicate is `Base.isless` (the default) and both inputs are sorted, this produces the sorted output.
Expand Down Expand Up @@ -1215,6 +1215,25 @@ _zip_longest_promote_shape(a, b) = promote_shape(a, b)
For one or more iterable objects, return an iterable of tuples, where the `i`th tuple
contains the `i`th component of each input iterable if it is not finished, and `default`
otherwise. `default` can be a scalar, or a tuple with one default per iterable.
```jldoctest
julia> for t in zip_longest(1:2, 5:8)
@show t
end
t = (1, 5)
t = (2, 6)
t = (nothing, 7)
t = (nothing, 8)
julia> for t in zip_longest('a':'e', ['m', 'n']; default='x')
@show t
end
t = ('a', 'm')
t = ('b', 'n')
t = ('c', 'x')
t = ('d', 'x')
t = ('e', 'x')
```
"""
zip_longest(its...; default=nothing) = ZipLongest(Tuple(_Padded.(its, default)))

Expand Down

0 comments on commit 9c6feb3

Please sign in to comment.