Jonathan Olsson
11/11/2022, 3:17 PMlet
function always been callable on nullable types (ie not <T : Any>
)? I could have sworn that the following didn't use to work:
fun foo(s: String?) {
s.let { } // <- expected I had to do s?.let { }
}
Has it always worked like this or was this changed at some point?Szymon Jeziorski
11/11/2022, 7:40 PMpublic inline fun <R, T : R> Result<T>.getOrElse(onFailure: (exception: Throwable) -> R): R
From the signature I would think that since T
is of type R
or its subtype, on Result<SubClass>
instance I could invoke getOrElse
only by passing lambda returning value of type which is super type to SubClass
.
Below code compiles perfectly fine, and I'm not sure why:
val x: Result<CharSequence> = runCatching { "string value" }
val z = x.getOrElse { 123 }
it would be logical for me that only lambdas returning super type of CharSequence
should be accepted, but I can pass whatever return type I want and this still works fine, it just makes inferred type of z
Result<Any>
. Am I missing something or should this not be expected behavior? Also, I cannot understand reason behind T : R
within function's declaration, if anything R : T
would be more logical to my understanding.Marc Knaup
11/12/2022, 12:06 AMInterface
needs to be a supertype of the class’s type parameter Implementation
.Racci
11/12/2022, 8:42 AMelect
11/12/2022, 9:16 AMdropWhile { it != line }.drop(1)
Is there a better way to do this?hfhbd
11/12/2022, 1:54 PMsealed class F {
object A: F()
object B: F()
}
fun F.foo(): F = when (this) {
is F.A -> F.A
is F.B -> F.B
}
val a: F.A = F.A.foo() // not possible without a cast
elect
11/12/2022, 2:33 PMnote
tag in kdoc?y
11/12/2022, 5:25 PMsequence
have an equivalent of Rust’s .next()
for `Iterator`s, which (lazily) returns the next item in the sequence if there is one, or null
otherwise?Darryl Pierce
11/12/2022, 7:24 PMPaul Doolittle
11/12/2022, 8:14 PMjanvladimirmostert
11/12/2022, 9:01 PM@Suppress("EnumEntryName")
enum class ConfigUri(val raw: String) {
login("/login"),
logout("/logout"),
register("/register"),
verify("/verify/{hash}"),
reset1("/reset"),
reset2("/reset/{hash}")
;
fun verify.build(hash: String): String = raw.replace("{hash}", hash)
}
in the endpoints where I declare the GET / POST handlers, I want to be able to do GET(ConfigUri.login.raw)
and in places where I need to fill in the hashes for example when sending out an email with a verify link, I want to be able to do ConfigUri.verify.build(hash = generatedRandomHash)
to generate something like /verify/12344-1324234-sdfsdfs
Aj0y
11/13/2022, 2:17 PMAj0y
11/13/2022, 2:23 PMAj0y
11/13/2022, 2:28 PMAj0y
11/13/2022, 2:29 PMAj0y
11/13/2022, 2:31 PMEllen Spertus
11/13/2022, 5:12 PMDarryl Pierce
11/13/2022, 5:21 PMBen Woodworth
11/13/2022, 9:57 PMacceptsString
I want to say R
can be constrained to String
by the smart cast but I'm not sure.
interface Accepts<in T> {
fun accept(value: T)
}
object AcceptsString : Accepts<String> {
override fun accept(value: String) = println(value)
}
fun <R> example(providesR: () -> R, acceptsR: Accepts<R>) {
if (acceptsR is AcceptsString) { // so R must be String
val acceptsString: AcceptsString = acceptsR
val providedR = providesR()
acceptsString.accept(providedR)
// ^^^^^^^^^ Type mismatch.
// Required: String
// Found: R
}
}
y
11/14/2022, 9:20 AMList<String>
, can I expect Kotlin to reuse this list, or will it allocate on every call to the function?LIRAN Y
11/14/2022, 11:05 AMprivate fun printAllPodsName() {
val podList = client.pods().inNamespace("default").list()
podList.items.forEach(Consumer { obj: Pod ->
println(obj.metadata.name)
})
}
now i want to go over this pod name list so it will check if the status is ready or not i tried to do something like this
fun waitUntilAllPodsAreReady() {
for (podname in printAllPodsName().toString()) {
client.pods().inNamespace("default").waitUntilCondition({ pods ->
pods.status != null && pods.status.conditions != null
}, 10, TimeUnit.MINUTES)
println(podname.toString())
}
}
but it seems like not working
any idea will be blessedShumilin Alexandr
11/14/2022, 1:15 PM@SpringBootApplication
class ApiApplication {
fun main(args: Array<String>) {
runApplication<ApiApplication>(*args) {
setBannerMode(Banner.Mode.OFF)
}
}
}
and this work! why?
@SpringBootApplication
class ApiApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(ApiApplication::class.java, *args)
}
}
}
rednifre
11/15/2022, 10:53 AMNuru Nabiyev
11/15/2022, 2:01 PMy
11/15/2022, 2:12 PMprivate set
to do this, but it seems like I can still mutate the value from outside the class.xun su
11/15/2022, 2:17 PM{ "refresh-token" : "some thing" }
I got error like this:LIRAN Y
11/15/2022, 4:29 PMfun execIntoContainer(podName: String, containerId: String, cmd: String) : String {
val future = CompletableFuture<Int>()
val listener = CompletableExecListener(future)
val out = ByteArrayOutputStream()
val error = ByteArrayOutputStream()
val command = cmd.split(" ").toTypedArray()
val exec = kubernetesClient.pods().withName(podName).inContainer(containerId)
.writingOutput(out)
.writingError(error)
.usingListener(listener)
.exec(*command)
future.get(10, TimeUnit.SECONDS)
exec.close()
if (error.toString().isEmpty()) {
return out.toString()
}
throw RuntimeException("Error from pod: $error")
}
it seems works just for one command.
when i add a grep for example (ls -ltr | grep t) it gave me an error and seems like the issue is with the split part
cmd.split(" ").toTypedArray()
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.RuntimeException: Error from pod: ls: cannot access '|': No such file or directory
ls: cannot access 'grep': No such file or directory
ls: cannot access 't': No such file or directory
any idea how can i use the split?Gavin Ray
11/15/2022, 7:26 PMOverload resolution ambiguity
for a function that has two varargs
single-argument signatures?
Overload resolution ambiguity. All these functions match.
public open fun <T : Any!> array(vararg values: TypeVariable(T)!): Field<Array<(out) TypeVariable(T)!>!> defined in org.jooq.impl.DSL
public open fun <T : Any!> array(vararg fields: Field<TypeVariable(T)!>!): Field<Array<(out) TypeVariable(T)!>!> defined in org.jooq.impl.DSL
It works in Java, but not in Kotlin. I can't use null
or `emptyArray()`/`emptyList()` because that produces the wrong results =/Anouar di Kali
11/16/2022, 12:50 AMPanos
11/16/2022, 7:50 PMlimitedParallelism
on Dispachers.IO but it is nowhere to be found despite me being on kotlinx coroutines 1.6.4. Am I missing something?