diff --git a/src/LazyGroupBy.jl b/src/LazyGroupBy.jl index d1c93ed..e0ffaa4 100644 --- a/src/LazyGroupBy.jl +++ b/src/LazyGroupBy.jl @@ -296,7 +296,7 @@ function _import_docs() try include_dependency(path) str = read(path, String) - str = replace(str, r"^```julia"m => "```jldoctest") + str = replace(str, r"^```julia"m => "```jldoctest $name") @eval @doc $str $name catch err @error( diff --git a/src/docs/reduce.md b/src/docs/reduce.md index 4ac27b8..177ea24 100644 --- a/src/docs/reduce.md +++ b/src/docs/reduce.md @@ -21,3 +21,33 @@ Transducers.GroupByViewDict{Bool,Mean{Float64,EqualWeight},…} with 2 entries: false => Mean: n=3 | value=1.33333 true => Mean: n=7 | value=4.71429 ``` + +An example for calculating the minimum, maximum, and number of each +group in one go: + +```julia +julia> using Transducers + +julia> table = ((k = gcd(v, 42), v = v) for v in 1:100); + +julia> collect(Iterators.take(table, 5)) # preview +5-element Array{NamedTuple{(:k, :v),Tuple{Int64,Int64}},1}: + (k = 1, v = 1) + (k = 2, v = 2) + (k = 3, v = 3) + (k = 2, v = 4) + (k = 1, v = 5) + +julia> counter = reducingfunction(Map(_ -> 1), +); + +julia> reduce.(TeeRF(min, max, counter), Map(x -> x.v), grouped(x -> x.k, table)) +Transducers.GroupByViewDict{Int64,Tuple{Int64,Int64,Int64},…} with 8 entries: + 7 => (7, 91, 5) + 14 => (14, 98, 5) + 42 => (42, 84, 2) + 2 => (2, 100, 29) + 3 => (3, 99, 15) + 21 => (21, 63, 2) + 6 => (6, 96, 14) + 1 => (1, 97, 28) +```