问题描述
在Julia中,我们有typeintersect(Missing, Union{Missing, Float64})
(返回Missing
).
In Julia we have typeintersect(Missing, Union{Missing, Float64})
(returning Missing
).Is it possible to get what remains instead (i.e. Union{Missing, Float64} - Missing
returning Float64
)?
我确实尝试过typesubtract(Missing, Union{Missing, Float64})
或typecomplement(Union{Missing, Float64}, Missing)
,但显然它们不存在;-)
I did try with typesubtract(Missing, Union{Missing, Float64})
or typecomplement(Union{Missing, Float64}, Missing)
but obviously they don't exist ;-)
推荐答案
对于Missing
,它实际上在Base中实现(但未导出)为nonmissingtype
函数.这里您有相关的代码:
For Missing
it is actually implemented in Base (but not exported) as nonmissingtype
function. Here you have the relevant code:
nonmissingtype(::Type{Union{T, Missing}}) where {T} = T
nonmissingtype(::Type{Missing}) = Union{}
nonmissingtype(::Type{T}) where {T} = T
nonmissingtype(::Type{Any}) = Any
因此,这可能应该可以解决Missing
(只是import
来自Base
的此功能)的问题,并且您有一个模板可以针对其他情况实现类似的功能.请让我知道它是否满足您的要求.
So this should probably solve your issue with Missing
(just import
this function from Base
) and you have a template how a similar thing can be implemented for other scenarios. Please let me know if it answers what you wanted.
这篇关于Julia中有类型减法运算吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!