gian
01/14/2020, 4:44 PMasad.awadia
02/01/2020, 2:28 PMasad.awadia
02/01/2020, 2:28 PMasad.awadia
02/01/2020, 2:28 PMCzar
02/01/2020, 3:44 PMasad.awadia
02/01/2020, 3:48 PMLeon K
02/21/2020, 12:26 PMitems.list.filter {}.map { it.depth }.max() ?: -1
?Mark
05/06/2020, 9:19 AM?.apply
or ?.also
but for doing the same when the value is null I end up doing something like
?: run {
…
null
}
or even ?: null.apply { ... }
Is there a way to write this without having to specify null
again?arekolek
05/06/2020, 10:00 AMinline fun <T> T.alsoIfNull(block: () -> Unit): T {
if (this == null) {
block()
}
return this
}
asad.awadia
05/15/2020, 3:45 PMString[] split = log.split(" ", 2);
and limit the split return to be of max size 2asad.awadia
05/15/2020, 3:45 PMasad.awadia
05/15/2020, 3:46 PM"asd".split(" ", 2)
??Marc Knaup
05/25/2020, 6:22 AM// base module provides registry
interface Feature
private val availableFeatureTypes = hashSetOf<String>()
inline fun <reified TFeature: Feature> registerFeature(feature: TFeature) {
availableFeatureTypes.add(typeNameOf<TFeature>())
// …
}
inline fun <reified TFeature: Feature> isFeatureAvailable() =
availableFeatureTypes.contains(typeNameOf<TFeature>()) // no 'NoClassDefFoundError' because inlined
// a module providing `SomeFeature` registers it by fully qualified name
object SomeFeature: Feature
fun someFunThatGetsCalledIfModuleIsUsed() {
registerFeature(SomeFeature)
}
// another module can optionally depend on SomeFeature
if (isFeatureAvailable<SomeFeature>()) { // no 'NoClassDefFoundError' because inlined
val feature = SomeFeature() // executed only if SomeFeature is available
// …
}
World that approach work in Kotlin Native or would it fail because everything is resolved at compile-time even if the code is never executed?asad.awadia
06/03/2020, 8:44 PM{
"foo": "bar",
"scores": [
{
"name": "foo",
"score": 0
},
{
"name": "bar",
"score": 10
},
{
"name": "foobar",
"score": 50
},
{
"name": "name",
"score": 20
}
]
}
Output:
{
"foo": "bar",
"scores": [
{
"name": "foo"
},
{
"name": "bar"
},
{
"name": "foobar",
"high_score": true
},
{
"name": "name"
}
]
}
asad.awadia
06/03/2020, 8:45 PMasad.awadia
06/03/2020, 8:45 PMKtrompfl
07/05/2020, 4:05 PMtoInt
, toIntOrNull
, ...) in kotlin.text
are implemented for String
instead of CharSequence
?diego-gomez-olvera
07/17/2020, 11:23 AMArrayList
diego-gomez-olvera
07/17/2020, 11:29 AMremoveIf
which has different optimized implementationsdiego-gomez-olvera
07/17/2020, 11:30 AMMarc Knaup
08/12/2020, 4:44 PMhashSetOf()
and toHashSet()
for Set
but hashMapOf()
and no toHashMap()
for Map
?
Also, according to the KEEP there should be a toSortedMap()
but elect
08/31/2020, 11:12 AMCharSequence.indexOfLast
passing also a String
instead of just a Char
?
Edit: found lastIndexOf
Abduqodiri Qurbonzoda [JB]
10/09/2020, 9:34 AMZac Sweers
02/08/2021, 6:29 PMCaseFormat
poohbar
02/10/2021, 3:29 AMfalse
if the code threw exception?breandan
05/20/2021, 5:33 PMresettableLazy
were part of the Kotlin standard library:
https://stackoverflow.com/questions/35752575/kotlin-lazy-properties-and-values-reset-a-resettable-lazy-delegatethana
06/07/2021, 8:16 AMZhelenskiy
07/01/2021, 8:24 PMDominaezzz
07/17/2021, 10:22 AM// do not introduce this overload --- too rare
//public fun <T, K> List<T>.binarySearchBy(key: K, comparator: Comparator<K>, fromIndex: Int = 0, toIndex: Int = size(), selector: (T) -> K): Int =
// binarySearch(fromIndex, toIndex) { comparator.compare(selector(it), key) }
dori
09/13/2021, 10:02 AM