Skip to content

Commit dc426da

Browse files
authored
remove confusing meta_table example (#231)
1 parent 5b80258 commit dc426da

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

docs/src/advanced.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,41 +91,6 @@ julia> sa.b
9191
2
9292
```
9393

94-
In the above example, our `MyType` was composed of `data` of type `Float64` and `rest` of type `NamedTuple`. In many practical cases where there are custom types involved it's hard for StructArrays to automatically widen the types in case they are heterogeneous. The following example demonstrates a widening method in that scenario.
95-
96-
```julia
97-
using Tables
98-
99-
# add a source of custom type data
100-
struct Location{U}
101-
x::U
102-
y::U
103-
end
104-
struct Region{V}
105-
area::V
106-
end
107-
108-
s1 = MyType(Location(1, 0), place = "Delhi", rainfall = 200)
109-
s2 = MyType(Location(2.5, 1.9), place = "Mumbai", rainfall = 1010)
110-
s3 = MyType(Region([Location(1, 0), Location(2.5, 1.9)]), place = "North India", rainfall = missing)
111-
112-
s = [s1, s2, s3]
113-
# Now if we try to do StructArray(s)
114-
# we will get an error
115-
116-
function meta_table(iter)
117-
cols = Tables.columntable(iter)
118-
meta_table(first(cols), Base.tail(cols))
119-
end
120-
121-
function meta_table(data, rest::NT) where NT<:NamedTuple
122-
F = MyType{eltype(data), StructArrays.eltypes(NT)}
123-
return StructArray{F}(; data=data, rest...)
124-
end
125-
126-
meta_table(s)
127-
```
128-
12994
The above strategy has been tested and implemented in [GeometryBasics.jl](https://github.com/JuliaGeometry/GeometryBasics.jl).
13095

13196
## Mutate-or-widen style accumulation

0 commit comments

Comments
 (0)