robstoll
01/08/2021, 2:33 PMjanvladimirmostert
01/08/2021, 3:53 PMvar i = 0
val map = mutableMapOf<String, Int>()
(1..10).forEach {
map["${++i}"] = ++i + i++
}
println(map)
{1=4, 4=10, 7=16, 10=22, 13=28, 16=34, 19=40, 22=46, 25=52, 28=58}
To ask it differently, is the IR being generated always such that map[...] evaluates first, then the ++i and then the i++ ?christophsturm
01/08/2021, 4:27 PMdm6801
01/09/2021, 8:27 AMfun main() {
fun fun1(name: String) = println("Hello $name")
val fun2 = { name: String -> println("Hello $name") }
function(::fun1)
function(fun2)
}
fun function(callback: (name: String) -> Any) {
//some complicated calculation
callback("username")
}
Which one would you use, and why?Chilli
01/09/2021, 12:44 PM[PublicAPI]
attribute in JetBrains Annotations .NET library) that would mark a class/method/… as public API and therefore stop showing warnings Property could be private
?CLOVIS
01/09/2021, 8:43 PMandries.fc
01/10/2021, 4:24 AMpaul Olukayode
01/10/2021, 5:42 PMSafa Orhan
01/11/2021, 10:41 AMAnimesh Sahu
01/12/2021, 4:10 AMscaventz
01/12/2021, 9:57 AMKotlinc
supports the option -script
, but I can’t find detailed information about it. Where can I find the relevant documentation about kotlin script?james
01/12/2021, 2:44 PMmikehearn
01/12/2021, 4:28 PMcrummy
01/12/2021, 6:27 PMmuliyul
01/13/2021, 12:22 AM[html...] SwaggerUIBundle({ ... }) // the object I'm trying to replace is the parameter to this factory
[...html]
The object may have indentation, new lines etc.
I came up with this:
html.replace("""\s*\{(\s*.*)*}\s*?""".toRegex(), myJsonFormattedString)
But since the expression resides between js brackets the regex is matching all the way to the closing bracket for example:
{ ... }) [...javascript] }
I tried to use the non-greedy modifier but it didn't seem to work.
Your help is appreciated!rajesh
01/13/2021, 9:03 AMArief Hidayat
01/14/2021, 7:15 AMArthur Artikov
01/14/2021, 11:16 AMAndrew Adams
01/15/2021, 12:01 AMinline fun <reified T : Any> T.Companion.extensionMethod = ...
holgerbrandl
01/15/2021, 8:51 AMelse
after a for loop it is executed when the loop terminates through exhaustion of the iterable but not when the loop is terminated by a break
statement. Here is the yet non-functional example from the python docs ported to kotlin
for(n in (2..10)){
for(x in (2.. n)){
if(n.rem(x)==0){
println("$n equals $x * ${n/x} ")
break
}
}
//todo else{ ???
// loop fell through without finding a factor
println("$ is a prime number")
}
natpryce
01/15/2021, 1:18 PMfun doSomethingWith(arg : SealedBaseClass, otherArg: Int) = when(arg) {
is SubclassA -> doSomethingWith(arg, otherArg)
is SubclassB -> doSomethingWith(arg, otherArg)
}
fun doSomethingWith(arg : SubclassA, otherArg: Int) = ...
fun doSomethingWith(arg : SubclassB, otherArg: Int) = ...
What do people think of the idea of a sealed function, where the compiler generates the when boilerplate for you?
E.g.
sealed fun doSomethingWith(arg : SealedBaseClass, otherArg: Int)
fun doSomethingWith(arg : SubclassA, otherArg: Int) = ...
fun doSomethingWith(arg : SubclassB, otherArg: Int) = ...
I’m imagining the same rules would apply as for sealed classes: all implementations of the sealed function have to be in the same source file. And the compiler would check them for exhaustiveness.Nir
01/15/2021, 4:01 PMclass BreakException : Exception("")
class Breaker {
fun breakOut() { throw BreakException(); }
}
class ForEachElser(val runElse: Boolean)
fun <T> Iterable<T>.forEachElse(func: Breaker.(t: T) -> Unit): ForEachElser {
val b = Breaker()
return try {
forEach{ b.func(it) }
ForEachElser(true)
}
catch (b: BreakException) {
ForEachElser(false)
}
}
infix fun ForEachElser.elser(func: () -> Unit) { if(runElse) func() }
Nir
01/15/2021, 4:32 PMelse
or other control flow, as above, then I'd like to be able to write:
something {
...
}
my_else {
...
}
but this will never compile, you need to put the my_else
after the brace. Does it seem reasonable at all that the compiler could consider allowing this to compile, specifically when you have an infix function starting a line like thatdMusicb
01/15/2021, 9:29 PMIfvwm
01/16/2021, 6:32 AMOliver Eisenbarth
01/16/2021, 11:48 AMRemy Benza
01/16/2021, 12:19 PMMutableList<Pair<Pair<String, Boolean>, Triple<String, String, Boolean>>>
type with the kotlinx serialization lib without writing a custom type converter?serebit
01/16/2021, 6:15 PMrobstoll
01/16/2021, 9:08 PMcomponent...
in the same line? So that something like the following would work:
val (a, (b, c)) = 1 to (2 to 3)
Zimri Leisher
01/17/2021, 2:37 AMZimri Leisher
01/17/2021, 2:37 AMAlexey Belkov [JB]
01/18/2021, 11:33 AMZimri Leisher
01/20/2021, 5:58 AM