jw
07/26/2019, 1:41 AMTestClock
feels like it should have `plusAssign`/`minusAssign` of a Duration
as a convenience. clock += 2.minutes
holgerbrandl
08/07/2019, 11:44 PMprintln(listOf(3, 263).hashCode())
println(listOf(5, 201).hashCode())
// -> 1317
println(Arrays.asList(3, 263).hashCode())
println(Arrays.asList(5, 201).hashCode())
// --> 40830
It's a more general problem as also the java example suffers from exactly the same problem. Interestingly, arrays with the same data give differnt hashes as documented at https://github.com/holgerbrandl/krangl/issues/75asad.awadia
08/10/2019, 10:51 PMvoddan
08/11/2019, 9:57 AMvar x: Int by map
Pavel Apisov
08/30/2019, 9:20 AMany
or all
returns true
with an empty list no matter what the predicate? Seems counterintuitive.
I tried to google it quickly but no luck.
Just wondering, maybe someone's aware of it and can explain 🙂nfrankel
09/05/2019, 8:30 PMStream.reduce(accumulator: BinaryOperator<T>)
returns an Optional<T>
it makes sense because if the stream is empty, the result will be empty
there’s another flavor providing an initial value and that returns a T
Stream.reduce(identity: T, accumulator: BinaryOperator<T>): T
that makes sense too
however, in kotlin
both Sequence.reduce()
(without initial value) and Sequence.fold()
(with an initial value)
return the same non-nullable type
actually, the code throws an exception if the sequence is empty
which seems not in line with what i would expect
a nullable value
why this behavior?
am i missing something?miha-x64
09/06/2019, 4:56 PMdr.dreigh
09/06/2019, 6:51 PMsequence.reduce
spand
09/18/2019, 9:08 AMList<E>.associateWithIndex(): Map<E, Int>
or something similar that I am missing. (edited)uliluckas
09/24/2019, 9:09 PMKProperty
?
if there was, one could write extension functions, depending on the delegate type. I.e.
fun KProperty<*, BehaviorRelayDelegate>.subscribe(O: Observer)
and use it like
val v : Int by BehaviorRelayDelegate(0)
::v.subscribe { Log("Value changed to $it" }
v = 2
val v1 = v
napperley
09/25/2019, 11:11 PMMarc Knaup
09/26/2019, 7:27 AMObjects.hash(foo, bar, baz, …)
to something like this?
hash { foo x bar x baz x … }
Just the boxing is a little tricky as well as getting it to work with just a single non-Int
value without introducing boxing.
Implementation:
inline fun hash(block: HashScope.() -> Int) =
HashScope.block()
object HashScope {
inline infix fun Any?.x(hashable: Any?) =
(31 * hashCode()) + hashable.hashCode()
inline infix fun Any?.x(hashable: Int) =
(31 * hashCode()) + hashable
inline infix fun Int.x(hashable: Any?) =
(31 * this) + hashable.hashCode()
inline infix fun Int.x(hashable: Int) =
(31 * this) + hashable
}
class Example(val foo: String, val bar: List<Any>?, val baz: Int) {
override fun hashCode() =
hash { foo x bar x baz }
}
Marc Knaup
09/26/2019, 7:43 AMClosedRange
have operators for destructuring?Dominaezzz
10/10/2019, 6:24 PM@kotlin.internal.InlineOnly
public inline fun buildByteArray(builderAction: ByteArrayOutputStream.() -> Unit): ByteArray
Mark
10/11/2019, 10:49 AMval CJK_EXTENSIONS_STR = fun (): String {
var result = "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_A}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_B}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_C}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_D}"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
result += "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_E}"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
result += "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_F}"
}
}
return result
}.invoke()
Dominaezzz
10/11/2019, 5:26 PMCloseable
in stdlib? I remember the verdict being stdlib itself doesn't use it so it won't provide it, but there should a ticket somewhere.spand
10/22/2019, 9:31 AMIterable<T>.groupByTo
requires destination to be a list and not a collection ?Bob Glamm
10/23/2019, 4:47 PMfun Pair<A, B>.flip(): Pair<B, A> = Pair(second, first)
to the standard libraryPHondogo
10/30/2019, 6:13 AMLeoColman
10/30/2019, 7:38 PMHullaballoonatic
10/31/2019, 4:42 PMDuration
in the stdlib, and I'm wondering if it could also have its own version of Date
that cleans up the mess that is Java's Date
, DateTime
, LocalDate
, LocalDateTime
PHondogo
11/02/2019, 11:23 AMDaniel Rust
11/04/2019, 7:53 PM!!
over checkNotNull
?bbaldino
11/06/2019, 9:00 PMResult
between 1.3.21 and 1.3.50? in 1.3.21 i can access it fine but can't find it in 1.3.50 (-Xallow-result-return-type
doesn't help either)Alpesh Vas
11/07/2019, 7:06 PMjimn
11/11/2019, 9:12 AMclass FrameGrouper(
private val origin: IDataFrame,
vararg val gby: Int
) : IDataFrame by origin {
override fun invoke(row: Int) =...}
Hullaballoonatic
11/11/2019, 10:20 PMinline fun <T, reified R> Array<T>.mapToArray(transform: (T) -> R) =
Array(size) { transform(get(it)) }
etc for List
, primitive arrays...Ruckus
11/12/2019, 2:49 PMinline infix fun Any?.hash(other: Any?): Int = hashCode() * 31 + other.hashCode()
It would simplify writing hashCode
functions:
class ABC<A, B, C>(val a: A, val b: B, val c: C) {
override fun hashCode() = a hash b hash c
}
Hullaballoonatic
11/20/2019, 6:46 PMList(7) { it + 3 }
a top level function instead of an static invoke operator? Is the latter somehow unintended usage of the language, or against standard code style?
static invoke operator is just so much more efficient than constructors, given you can error check prior to instantiation, among many other things. I can see how it can read very alien to those not kotlin-savvy, however.Dominaezzz
11/20/2019, 10:27 PMfun CharSequence.splitToSequences(
vararg delimiters: String,
ignoreCase: Boolean = false,
limit: Int = 0
): Sequence<CharSequence>