Based on a problem I encountered, I think that it would be a nice addition to the language.
map.valueOf(key)
// which is equal to
map[key]
This enables the null-safe operator:
map?.valueOf(key)
This already exists for iterables, where:
list.elementAt(index)
// is equal to
list[index]
We are not planning on adding a duplicate method. That's bad API design just to make up for a lacking language feature.
We should consider extending null-aware behavior to operators, or at least the index operators. We already allow them for cascades, and we want null-aware operators to extend to the end of the same section like cascades do.
So, maybe at least allow x?.[42] and x?.[42] = 10 like we allow x..[42].toString() and x..[42] = 10.
Most helpful comment
We are not planning on adding a duplicate method. That's bad API design just to make up for a lacking language feature.
We should consider extending null-aware behavior to operators, or at least the index operators. We already allow them for cascades, and we want null-aware operators to extend to the end of the same section like cascades do.
So, maybe at least allow
x?.[42]andx?.[42] = 10like we allowx..[42].toString()andx..[42] = 10.