First time caller, long time listener.
I have an issue that could use some elucidation.
The intent is to traverse a structure and transform a set of primitive types to string, whilst preserving structure. Given this example code…
def to_stringly(value)
  case value
  when Array, Tuple
    value.map { |v| to_stringly(v) }
  when Hash
    value.transform_values { |v| to_stringly(v) }
  when NamedTuple
    to_stringly(value.to_h)
  when String, Bool
    value
  else
    value.to_s
  end
end
body = {
  :compare => [
    {
      :key    => "key",
      :value  => 0,
      :target => "VERSION",
      :result => "EQUAL",
    },
  ],
  :success => [
    {
      :request_put => {
        :key   => "key",
        :value => "value",
      },
    },
  ],
  :failure => [] of Nil,
}
to_stringly(body)
Results in the following error…
error in line 47
Error: instantiating 'to_stringly(Hash(Symbol, Array(Hash(Symbol, Hash(Symbol, String))) | Array(Hash(Symbol, Int32 | String)) | Array(Nil)))'
error in line 14
Error: instantiating 'to_stringly((Array(Hash(Symbol, Hash(Symbol, String))) | Array(Hash(Symbol, Int32 | String)) | Array(Nil)))'
error in line 8
Error: instantiating 'to_stringly((Hash(Symbol, Hash(Symbol, String)) | Hash(Symbol, Int32 | String)))'
error in line 10
Error: type must be Hash(Symbol, String), not (Hash(Symbol, String) | String)
Shouldn’t the union be an acceptable argument given the type refinement of the case statement?
Thanks!