mikrobak
12/28/2016, 12:16 AMpedrol
12/28/2016, 12:18 AMget(key) ?: defaultValue()
vishal-reddy
12/28/2016, 12:18 AMval map = mapOf("foo" to 1, "bar" to null)
val x = map.getOrElse("bar") { null }
val y = x ?: throw Exception("bad stuff”)
mikrobak
12/28/2016, 12:20 AMgetOrElse
.
getOrElse
currently doesn't recognise null
as a legitimate value that could be in the map. And it should IMO.pedrol
12/28/2016, 12:21 AMpedrol
12/28/2016, 12:21 AMmikrobak
12/28/2016, 12:21 AMgetOrElse
should be something along the lines of
if (containsKey(key)) get(key) else defaultValue()
kevinmost
12/28/2016, 12:22 AMcontainsKey
as well, personallypedrol
12/28/2016, 12:23 AMcontainsKey
mikrobak
12/28/2016, 12:24 AMmikrobak
12/28/2016, 12:25 AMpedrol
12/28/2016, 12:25 AMgetOrElseNullable
mikrobak
12/28/2016, 12:25 AMpedrol
12/28/2016, 12:25 AMpedrol
12/28/2016, 12:25 AMkevinmost
12/28/2016, 12:26 AMgetOrElse
as it's implemented just doesn't seem useful to me. Why would I do map.getOrElse("foo") { defaultValue }
when I could do map["foo"] ?: defaultValue
which is much more idiomatic?mikrobak
12/28/2016, 12:28 AMnull
to be treated as a pseudo-error-code for a lack of a key in the map when using getOrElse
pedrol
12/28/2016, 12:33 AMmikrobak
12/28/2016, 12:33 AMmikrobak
12/28/2016, 12:35 AMdouglarek
12/28/2016, 1:12 AMmap.getOrElse("foo") { defaultValue }
can be multiple lines while map["foo"] ?: defaultValue
can not be a fun blockhackerham
12/28/2016, 1:18 AMdouglarek
12/28/2016, 1:23 AMmap.getOrElse("foo") { defaultValue }
mzgreen
12/28/2016, 9:19 AMall-open
plugin for specific configurations? For example only when running tests?yoavst
12/28/2016, 10:17 AMvar x: Float = 0
Is this syntax going to be supported?mobigeek
12/28/2016, 10:18 AMvar x = 0f
not being simpler?miha-x64
12/28/2016, 10:18 AMvar x: Float = 0f
is OK alsoyoavst
12/28/2016, 10:20 AMenleur
12/28/2016, 10:20 AMvar x = 0.0
?miha-x64
12/28/2016, 10:20 AM