gregorbg
03/20/2019, 5:15 PMget
operator returning Nullable?
types for Maps but not for Lists? I understand that in a map, you may not know whether the key is set. But in a List, you may not know whether the index exists (i.e. the list is long enough) either??!Shawn
03/20/2019, 5:19 PMindex < list.size
, but I suppose a better explanation is that maps or, more broadly, associative arrays allow for arbitrary mappings of keys to values, with no imposed relation between the keys, except for maybe data type (which you can get around with just a Map<Any, Value>
)null
if a key isn’t found because there isn’t necessarily a structural constraint that lets you easily and inexpensively tell if a key should be theregregorbg
03/20/2019, 5:24 PMgetValue(key)
even within a if (key in myMap.keys)
branchShawn
03/20/2019, 5:28 PMgetValue()
can be avoided by just using the null-safety navigator and composing the operations you need to perform by way of ?.let { ... }
, takeIf { ... }
, etckarelpeeters
03/20/2019, 5:35 PMgregorbg
03/20/2019, 8:01 PMCzar
03/21/2019, 10:26 AM