Add `keytype`+`valtype` method for AbstractArray and AbstractVector (#27749)
* Add keytype method for AbstractArray and AbstractVector
The function `keytype(a)` returns `eltype(keys(a))` for associative
structures; it should do the same for `Abstract{Array, Vector}`.
* Add keytype method for AbstractArray and AbstractVector (part 2)
Now also for the type, not just for objects.
* Add valtype(...) for arrays
Arrays are associative structures in the sense that keys(...)
and values(...) both work on them. When considering them as such, their
valtype should be equal to eltype. (A future version of Julia could
even do `const valtype = eltype`?)
* Implement keytype/valtype for object as keytype(typeof(...
As suggested by @mbauman in code review.
Co-Authored-By: tkluck <tkluck@infty.nl>
* Implement keytype/valtype for ranges
* Add test cases for keytype/valtype(::AbstractArray)
* Add #27749 to NEWS.md
* keytype/valtype for arrays: docs + compat annotation
* keytype/valtype: use String values in examples
this makes the distinction between key and value clearer. Thanks to @StefanKarpinski for suggesting this.
Co-Authored-By: tkluck <tkluck@infty.nl>
* keytype/valtype for arrays: no special treatment for ranges
This was a little red herring in the discussion in #27749:
the `length` of a range may depend on the type of its parameters,
but as it turns out, `eltype(keys(...))` does not.
That's arguably a bug/inconsistency, but it's outside of the
scope of this pull request to fix that.