hmole
09/21/2018, 6:49 AMthing.map(otherThing::method<MyType>)
. I've tried putting brackets everywhere and it doesn't work ☹️vmichalak
09/21/2018, 1:06 PManstaendig
09/23/2018, 5:13 PMjw
09/24/2018, 6:13 PMelect
10/10/2018, 12:46 PMiterator()
on `Enum`s, so that we can write for(e in enum)
? Instead of e in enum.values()
which, I guess, implies an array copy?miha-x64
10/10/2018, 1:49 PMpublic operator fun <T> Array<T>.plus(elements: Array<out T>): Array<T>
have out
receiver variance?
enum class A { A }
enum class B { B }
val sum = A.values() + B.values()
// adding the following function makes the code above work:
private inline operator fun <reified T> Array<out T>.plus(elements: Array<out T>): Array<T> {
val sum = arrayOfNulls<T>(size + elements.size)
System.arraycopy(this, 0, sum, 0, size)
System.arraycopy(elements, 0, sum, size, elements.size)
return sum as Array<T>
}
Hamza
10/10/2018, 2:42 PMghedeon
10/11/2018, 3:04 PMArrays.binarySearch() / IntArray.binarySearch()
that accepts comparator argument? The way it works now, it's possible to perform a binarySearch
in an ascending IntArray
but not in a descending. At the same time, no problems with Array<Int>
.littlelightcz
10/11/2018, 7:10 PMList<Result<T>>
(when using runCatching {}
) which would help be execute some action in case there have been some failures etc.? Since I think this is (or will be) a very common design pattern - similarly as there is a convenience ext. function for List<Deferred<T>>.awaitAll()
.
Recently I was thinking it could be done in the similar fashion as the current .onFailure()
and .onSuccess()
except that the lambda would take List<Throwable>
or List<T>
as an argument (respectively).
Currently what I need to do on such list, is: (1) filter { it.isFailure}
, then (2) I need to check that it is not empty, and not until now (3) I can do something with it. With the above proposal the first 2 steps would be unnecessary and I would be able to define just the part which would execute only if there was at least 1 failed Result. Similarly it could work for successful Result values.karelpeeters
10/31/2018, 6:26 PMIterable<Pair<K, V>>.toMutableMap()
is "missing", that confused me for a second simple smilehmole
11/07/2018, 11:09 AMval (a,(b,c)) = 1 to (2 to 3))
?louiscad
11/14/2018, 2:47 PMinline operator fun <R> KProperty0<R>.getValue(thisRef: Any?, property: KProperty<*>): R = get()
inline operator fun <R> KMutableProperty0<R>.setValue(thisRef: Any?, property: KProperty<*>, value: R) {
set(value)
}
Here's a link to an example snippet: https://pl.kotl.in/HyLn42KaQhho
11/15/2018, 11:32 AMlistOf(*yourArray)
?guenther
11/15/2018, 12:56 PMByte
looks like this:
public class Byte private constructor() : Number(), Comparable<Byte> {
companion object {
public const val MIN_VALUE: Byte = -128
public const val MAX_VALUE: Byte = 127
...
Double
on the other hand looks like this:
public class Double private constructor() : Number(), Comparable<Double> {
companion object {
public val MIN_VALUE: Double
public val MAX_VALUE: Double
...
Is there are a particular reason, why the properties in Double
are not const
?
This prevents me to use those properties in my own constants.dave08
11/15/2018, 5:38 PMassociateWithNotNull { }
for when the value is resolved to be null
, just like mapNotNull { }
?gabrielfv
11/29/2018, 4:30 PMIterable
class, which takes a (T) -> Boolean
predicate and returns IndexedValue<T>
?gabrielfv
11/29/2018, 4:31 PMfor (a in withIndex()) ...
rather than var i = 0; for (a in iterable) { ...; a++ }
?Mark
11/30/2018, 7:23 AMif (arg == null) null else myfun(arg)
? I can only think of arg?.let { myfun(it) } ?: null
but this seems less readable to me.spand
12/06/2018, 12:49 PMreduce
that works for empty collections by returning null
?
I can see that there are specializations of it (.minBy
, .minWith
, ..) but a general version escapes me.Dias
12/06/2018, 11:17 PMrrader
12/08/2018, 2:55 PMEither
class? https://www.scala-lang.org/api/2.9.3/scala/Either.htmlMarc Knaup
12/11/2018, 8:18 AMinline fun <R> Boolean.thenTake(action: () -> R) =
if (this) action() else null
val result = if (input) something() else null
->
val result = input.thenTake { something() }
stevecstian
12/12/2018, 9:18 AMeachCount
is not listed in https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-grouping/index.html#extension-functions now? Did I miss anything?cbruegg
12/13/2018, 7:18 PMequals
correctly, the class needs to be identical and not just be subclasses of the same type.Dias
12/17/2018, 2:44 PMShawn
12/17/2018, 2:46 PMzipWithNext
will group items together into pairs if that works for yourobin
12/18/2018, 10:19 AMSequence<T>.partition
is Pair<List<T>, List<T>>
, and not Pair<Sequence<T>, Sequence<T>>
? It would be nice to keep the lazyness even through a partitioning operation.thomasnield
12/18/2018, 9:28 PM(-4.0).pow(1.0/3.0)
, which returns NaN
due to lack of support for imaginary numbers. However, Java has Math.cbrt()
specifically for this purpose. Is this something Kotlin should explicitly support?Dias
12/19/2018, 5:00 PMString.toInt()
just an alias for parseInt()
, but String.toIntOrNull()
is custom implementation instead of trycatch implementation of parseInt()? Is it because throwing exceptions in java is heavy or something like that?rrader
12/24/2018, 1:35 PMIllegalArgumentException
with another exception? that will store property name and will be possible to get that property name and not to parse the error string