Open Moelf opened 1 year ago
A possible implementation is to define
# need a better name
AwkwardArray.akconvert(x) = x #default no-op
and then define from_iter
to something like:
function from_iter(input)
ItemType = eltype(input)
AwkwardType = layout_for(ItemType)
out = AwkwardType()
for item in input
push!(out, Awkward.akconvert(item))
end
out
end
and the user-facing interface/contract for custom type is: if you have a custom type, you need to specialize two functions:
AwkwardArray.layout_for(::Type{MyType})
which must return a type that is (eventually) recognized by AwkwardAwkwardArray.akconvert(x::MyType)
which must convert to the same type as returned by 1I'm open to any such changes, even if they change the interface. Nothing is firmly established yet.
I'm test driving using a function from AK as a
sink
to UnROOT:This works but is not very ergonomic and also involves copying everything twice.
Because
LazyTree
is already iterable, I tried to get the following to workthen I hit a infinite recursion:
to me it all just means that:
for ... push!() end
to_layout
andfrom_iter
a little bit to allow easy custom typeWhat I really want to do here is to tell
AwkwardArray
:evt::LazyEvent
, you can just callcollect(evt)
first and you will get aNamedTuple
which you know how to handle