If I define
const Maybe{T} = Union{T,Nothing}
How to “pop” the T
type from Maybe
? I want to do this because I have the following type
using Parameters
@with_kw struct A
a::Maybe{String} = nothing
b::Maybe{Float64} = nothing
c::Maybe{Int} = nothing
d::Int = 1
end
I want to parse this type from matched strings by
[parse(fieldtype(A, f), match(regex, str)[1]) for (f, regex) in zip(fieldnames(A), REGEXES)]
where each field f
is associated with a regex
.
Of course, I can use setdiff
to kick Nothing
out of that Maybe
. But the code looks ugly…
Another problem is that I cannot parse
a String
from a String
, but that is not a big deal.