diff --git a/src/base.jl b/src/base.jl index c2957d9..e8afa24 100644 --- a/src/base.jl +++ b/src/base.jl @@ -1,8 +1,10 @@ # predefined adaptors for working with types from the Julia standard library -# Use recursion on tuples to avoid inference bail-out in `map` +# Use recursion to avoid inference bail-out in `map` #adapt_structure(to, xs::Union{Tuple,NamedTuple}) = map(adapt(to), xs) -adapt_structure(to, xs::NamedTuple) = map(x->adapt(to,x), xs) +adapt_structure(to, xs::NamedTuple{names}) where {names} = + NamedTuple{names}(adapt_structure(to, Tuple(xs))) + adapt_structure(to, xs::Tuple) = _adapt_tuple_structure(to, xs) _adapt_tuple_structure(to, xs::Tuple) = (adapt(to, first(xs)), _adapt_tuple_structure(to, Base.tail(xs))...)