Skip to content

Commit

Permalink
Fix inference for adapt_structure with NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Mar 5, 2024
1 parent 94f809a commit 682635f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
@@ -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))...)
Expand Down

0 comments on commit 682635f

Please sign in to comment.