aiac
1
code
def is_struct?(t : T) : Bool forall T
{% begin %}
{{ T.struct? }}
{% end %}
end
p! is_struct? 1
p! is_struct? 1.0
p! is_struct? StaticArray[0]
output
is_struct?(1) # => false
is_struct?(1.0) # => false
is_struct?(StaticArray[0]) # => true
aiac
2
how to detect primitive type?
T.primitive?
I don’t think there’s a built-in way to do this?
2f1cafc
4
Could you check whether it’s a sub-type of Value
?
def is_value?(t : T) : Bool forall T
{% begin %}
{{ T < Value }}
{% end %}
end
2 Likes