You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an unfortunate consequence of how Julia's type inference work. In Rocket.jl the operator map(ExpectedType, MappingFn) expects that the MappingFn always returns an instance of type ExpectedType. However, in your case this property does not hold:
julia> val =11
julia> data = (value = val <2?nothing: val, )
(value =nothing,)
julia>typeof(data) isa NamedTuple{(:value,), Tuple{Union{Nothing, Int64}}}
false
This happens because Julia infers typeof(data) as NamedTuple{(:value,), Tuple{Nothing}} and this is not the same as NamedTuple{(:value,), Tuple{Union{Nothing, Int64}}}.
This has nothing really to do with the Rocket.jl library and relates to the type-inference machinery of the Julia programming language, but luckily you have at least two workarounds for this.
Workaround 1
Use the @NamedTuple macro explicitly to force Julia to use the ExpectedType as of following:
The @NamedTuple macro exists precisely for this type of cases in the Julia language.
Workaround 2
Use Any as the ExpectedType. In this way you don't specify any constraints on the output type and it should not have any performance penalties unless you chain other operators after the map operator.
MWE:
Errors with:
The text was updated successfully, but these errors were encountered: