|
| 1 | +""" |
| 2 | + LazyRow(s::StructArray, i) |
| 3 | +
|
| 4 | +A lazy representation of `s[i]`. `LazyRow(s, i)` does not materialize the `i`th |
| 5 | +row but returns a lazy wrapper around it on which `getproperty` does the correct |
| 6 | +thing. This is useful when the row has many fields only some of which are |
| 7 | +necessary. It also allows changing columns in place. |
| 8 | +
|
| 9 | +See [`LazyRows`](@ref) to get an iterator of `LazyRow`s. |
| 10 | +
|
| 11 | +# Examples |
| 12 | +
|
| 13 | +```julia-repl |
| 14 | +julia> t = StructArray((a = [1, 2], b = ["x", "y"])); |
| 15 | +
|
| 16 | +julia> LazyRow(t, 2).a |
| 17 | +2 |
| 18 | +
|
| 19 | +julia> LazyRow(t, 2).a = 123 |
| 20 | +123 |
| 21 | +
|
| 22 | +julia> t |
| 23 | +2-element StructArray(::Array{Int64,1}, ::Array{String,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}: |
| 24 | + (a = 1, b = "x") |
| 25 | + (a = 123, b = "y") |
| 26 | +``` |
| 27 | +""" |
1 | 28 | struct LazyRow{T, N, C, I} |
2 | 29 | columns::StructArray{T, N, C, I} # a `Columns` object |
3 | 30 | index::I |
@@ -29,6 +56,20 @@ iscompatible(::Type{<:LazyRow{R}}, ::Type{S}) where {R, S<:StructArray} = iscomp |
29 | 56 |
|
30 | 57 | (s::ArrayInitializer)(::Type{<:LazyRow{T}}, d) where {T} = buildfromschema(typ -> s(typ, d), T) |
31 | 58 |
|
| 59 | +""" |
| 60 | + LazyRows(s::StructArray) |
| 61 | +
|
| 62 | +An iterator of [`LazyRow`](@ref)s of `s`. |
| 63 | +
|
| 64 | +# Examples |
| 65 | +
|
| 66 | +```julia-repl |
| 67 | +julia> map(t -> t.b ^ t.a, LazyRows(t)) |
| 68 | +2-element Array{String,1}: |
| 69 | + "x" |
| 70 | + "yy" |
| 71 | +``` |
| 72 | +""" |
32 | 73 | struct LazyRows{T, N, C, I} <: AbstractArray{LazyRow{T, N, C, I}, N} |
33 | 74 | columns::StructArray{T, N, C, I} |
34 | 75 | end |
|
0 commit comments