jw
08/17/2018, 3:31 PMa.intersect(b).let { (a - it) to (b - it) }
evanchooly
08/17/2018, 3:32 PMevanchooly
08/17/2018, 3:32 PMjw
08/17/2018, 3:32 PMLeoColman
08/22/2018, 1:37 PMLeoColman
08/22/2018, 1:37 PMLeoColman
08/22/2018, 1:37 PMmg6maciej
08/30/2018, 10:47 AMfun <T> T?.orElse(t: T): T
function in stdlib?hho
08/30/2018, 10:52 AM?:
hho
08/30/2018, 10:52 AMmg6maciej
08/30/2018, 10:56 AMx ?: 0 < 10
...mg6maciej
08/30/2018, 10:56 AMmiha-x64
08/30/2018, 12:30 PM(x ?: 0) < 10
is more readablelittlelightcz
09/22/2018, 11:42 AMInt
and Long
types had extension functions: isOdd()
and isEven()
. I found myself doing if (it % 2 == 0)
many times ... especially in tests.anstaendig
09/23/2018, 5:13 PMval Int.isOdd: Boolean = this % 2 == 0
karelpeeters
09/23/2018, 5:18 PMval Int.isOdd: Boolean get() = this % 2 == 0
anstaendig
09/23/2018, 5:20 PManstaendig
09/23/2018, 5:20 PManstaendig
09/23/2018, 5:20 PMkarelpeeters
09/23/2018, 5:22 PManstaendig
09/23/2018, 5:22 PMkz
09/23/2018, 5:46 PMget()
because an extension property can't create a backing field. If you think about how this is implemented it makes sense. This just turns into a static function that accepts this
as a parameter. You can't add any state to the receiver that it doesn't already supportanstaendig
09/23/2018, 5:54 PMFleshgrinder
09/24/2018, 6:12 PMTom Adam
10/31/2018, 4:26 PMthomasnield
11/05/2018, 4:39 PMthomasnield
11/05/2018, 4:39 PMdave08
11/07/2018, 3:05 PMpublic inline fun <K, V> ConcurrentMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V {
// Do not use computeIfAbsent on JVM8 as it would change locking behavior
return this.get(key)
?: defaultValue().let { default -> this.putIfAbsent(key, default) ?: default }
}
The problem is that if defaultValue
returns null
, putIfAbsent
will crash with an NPE... is there a way to ensure that it should not be able to receive nulls?dave08
11/07/2018, 3:06 PMV
seems to accept `null`s...karelpeeters
11/07/2018, 3:14 PMputIfAbsent
(and for most of the other collections functions) says:
throws- if the specified key or value is null, and this map does not permit null keys or valuesNullPointerException