voddan
02/13/2018, 9:05 AMreplace
function
inline fun CharSequence.replace(regex: Regex, noinline transform: (MatchResult) -> CharSequence): String
And found out that I can't easily destructure the lambda parameter and have to use MatchResult.destructured
instead
http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/destructured.html
Why the most intuitive usage text.replace(Regex("(\\d+)(\\w+)")) { (digits, letters) -> ""}
was not supported?
What's the point of having a separate wrapper for desctructuring? http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-match-result/-destructured/index.html
Shouldn't we add componentN()
extension function to MatchResult
?ilya.gorbunov
02/13/2018, 2:38 PMWhat's the point of having a separate wrapper for desctructuring?The wrapper changes the group numbering, so that
component1
corresponds to the group with index 1, rather than 0.
We had experimented with the design when MatchResult
can be destructured immediately, but found that very confusing https://discuss.kotlinlang.org/t/public-review-of-the-standard-library-apis-closed/1362/76ilya.gorbunov
02/13/2018, 2:59 PMkevinmost
02/15/2018, 3:11 PMwakingrufus
02/16/2018, 3:08 AMmg6maciej
02/26/2018, 5:13 PMraulraja
02/26/2018, 7:07 PMdata class Tuple3<A, B, C>(val a: A, val b: B, val c: C)
fun <A, B, C> List<A>.zip(g: List<B>, h: List<C>): List<Tuple3<A, B, C>> =
this.zip(g).zip(h).map { (ab, c) ->
val (a, b) = ab
Tuple3(a, b, c)
}
fun main (args: Array<String>) {
val l1: List<Int> = listOf(1, 2, 3)
val l2: List<Char> = listOf('1', '2', '3')
val l3: List<String> = listOf("1", "2", "3")
val zipped: List<Tuple3<Int, Char, String>> = l1.zip(l2, l3)
println(zipped) //[Tuple3(a=1, b=1, c=1), Tuple3(a=2, b=2, c=2), Tuple3(a=3, b=3, c=3)]
}
jw
02/27/2018, 1:34 AMfunc: (A, B, C) -> T = ::Triple
if you canstepango
03/03/2018, 8:41 AMkotlin.internal.contracts
is used for?Aregev2
03/06/2018, 9:03 AMjw
03/06/2018, 11:45 PMjava.lang.Math
(which is required for #multiplatform)asad.awadia
03/06/2018, 11:48 PMfor(x in 0 until prices.size) {
if(prices[x]<min) min=prices[x]
else max=Math.max(max,prices[x]-min)
}
on leetcode took 332msmarcinmoskala
03/07/2018, 9:48 AMval minPrize = prices.min()
val maxProfit = prices.min() - minPrize
?elect
03/07/2018, 10:35 AMval color = Vec4()
val vertexData = floatArrayOf(*color)
mg6maciej
03/07/2018, 10:56 AMsomeMap.filterValues { it != null }.mapValues { it.value as Any }
or is there anything like someList.filterNotNull()
for `Map`s?diesieben07
03/08/2018, 11:16 PMorg.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.30
I cannot use use
on AutoCloseable
, is that correct? How can I "use" an AutoCloseable
?holgerbrandl
03/15/2018, 1:33 PMboolarr.contains(true)
. An IDE warning here would be nice indeed.holgerbrandl
03/15/2018, 2:00 PMrrader
03/19/2018, 10:44 AMgroostav
03/19/2018, 10:13 PMpublic infix fun <T> Iterable<T>.intersect(other: Iterable<T>): Set<T> {
val set = this.toMutableSet()
set.retainAll(other)
return set
}
public fun <T, C> Iterable<T>.intersect(other: Iterable<T>, comparator: (T, T) -> Boolean) { //...
holgerbrandl
04/04/2018, 2:49 PMkotlin.Throwable
isn’t extending java.lang.Throwable
. Also the docs are not too helpful: https://kotlinlang.org/docs/reference/exceptions.html states that
All exception classes in Kotlin are descendants of the class Throwablebut I could not find any example in the stdlib. E.g. see kotlin.KotlinNullPointerException as a counter-example.
Aregev2
04/04/2018, 3:44 PMAregev2
04/04/2018, 10:30 PMbrescia123
04/16/2018, 8:29 AMpublic inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean
with my colleagues and I realized that a lot of them have different intuitive expectations about the output of the function when called on an empty list. Can someone provide some insights about the decision of make it return true
if the list is empty? Thanks!dimsuz
04/18/2018, 2:31 PMone two three
-> one two\nthree
.
There's replaceFirst
, but no replaceLast
Dave Leeds
04/19/2018, 3:14 AMtypealias
is used. I've found that it's most frequently used to map some common classes (e.g., exceptions, StringBuilder
, ArrayList
, Serializable
) to the corresponding Java classes. I was curious if @ilya.gorbunov or someone else at JB can fill me in on the purpose of these particular aliases in the standard library. Are they intended to save on imports (e.g., no need to import java.util.*
if ArrayList
is found in kotlin.collections
)? Or to give Kotlin the flexibility to expand on the interface of those classes in the future? Or something else? Thanks!kz
04/26/2018, 3:07 PMthis
reference? I'm using Apache Spark and my jobs is failing due to the task not being serializable because one of my lambda's generated class includes the SparkJob
reference (which I don't want Serializable
). The reference is included as a class field even though it's not actually accessed.
Then in my other spark jobs I have plenty other lambdas that also don't access the this
reference and properly do not have that code generated.voddan
06/05/2018, 11:21 AM5.pow(4)
I expect it to perform the most efficient way, using the information that both arguments are integersAregev2
06/14/2018, 5:26 AM