Support for Hash.of

In the same vain that it is possible to specify a Types::Strict::Array.of(Types::Strict::String), it would be nice to support specifying the expected types for keys and values in a Hash. Something like Types::Strict::Hash.of(keys: Types::Strict::Symbol, values: Types::Strict::String).

It is already possible to define a schema for Hash, but I find a lot of times with the situation where I’m going to use a Hash with unknown keys but with expected key/value types. What do you think?

@waiting-for-dev I think you might be describing Types::Hash.map?

@timriley I think you are right :smile: I completely missed that part of the docs. Sorry for the noise and thanks for pointing me toward the right resource :smile:

Quite recently somebody asked about this and I said “there’s no such thing” and then Nikita showed up and said "well, actually…there’s Types::Map". So, yeah :laughing:

1 Like

It was my fault for sure because it is very well documented and the documentation is very accessible, but maybe we have a little naming inconsistency here… I think it would be more consistent to name Array.of and Hash.of, or something like Array.list and Hash.map :slight_smile: