Manuel Pérez Alcolea
09/25/2020, 10:55 PMval function: ((Char) -> Unit) = ::println
println(function)
something like
println(::println) // but this fails because it's ambiguous
Ayden
09/26/2020, 4:14 AMRishit Dagli
09/26/2020, 7:09 AMEmmanuel Oga
09/26/2020, 7:29 PM<http://logger.info|logger.info>("${PERFORM POTENTIALLY EXPENSIVE LOGGING OP}")
, so even if I configure the logger to only log errors, the info call will still incur the cost of the expensive operation, with no message being logged. Would be nice to have it so the logging doesn't even happen at all unless I turn it on.TwoClocks
09/27/2020, 12:34 AMharoldadmin
09/27/2020, 5:05 AM<meta>
tags on a webpage.Allan Wang
09/27/2020, 9:29 AMList<Char>
to String
or should we just use joinToString
? I’m trying to shuffle letters in a word and I’m doing so by String.toList().shuffled()
vlad.minaev
09/27/2020, 10:48 AMYan Pujante
09/27/2020, 2:27 PMMichael de Kaste
09/28/2020, 9:04 AMval hasMyPredicate = someObject.someField.hisField.finalField != null
val someOtherBoolean = extensiveFunction()
when{
hasMyPredicate && someOtherBoolean -> {...}
!hasMyPredicate && someOtherBoolean -> {...}
!hasMyPredicate && !someOtherBoolean -> {...}
hasMyPredicate && !someOtherBoolean -> { val value = someObject.someField.hisField.finalField //value is nullable here, but the precondition made sure that it isn't }
}
How can I reference a deep inner value to be non-null and then when accessed it is autotyped to be non-null
I absolutely hate using !! and especially error("...") if the chain of access calls are all on non-settable values (they are all val)vio
09/28/2020, 12:01 PMobject A {
val a = ...
object B {
val b = ...
}
}
and I'm accessing b like this: A.B.b
(which is what I need)
but I would like to move class B into another file, and still acces b
the same way
and I can't find the right way to define it
I would like to have something like bellow (this is not a valid code):
object A.B {
val b = ...
}
Is there a way to get something similar?
Thank you in advance!Ben Toofer
09/28/2020, 3:04 PMVersion
) which can be extended to defined a specific object structure. I then have a defined type VersionDefinition<V extends Version>
which has a simple data structure to it but it is restricted to implement the keys of the specified version ([x in keyof V]
)
// Defining a map interface of a key type string and value type of any
interface Version {
[key: String]: any
}
// Defining an object type that enforces the implementation of the specified version (V)
type VersionDefinition<V extends Version> = {
[x in keyof V]: {
description: String,
headerName: FakeHeader,
}
}
// Version 1 interface
interface Version1 extends Version {
foo: Integer,
bar: Integer,
...
}
// Version 1 implementation
const VERSION_1_DEFINITION: VersionDefinition<Version1> = {
foo: {
description: "Bar description",
headerName: FakeHeader.FOO
},
bar: {
description: "Bar description",
headerName: FakeHeader.BAR
}
...
}
I know I can create the Version1
interface as a data class in Kotlin but my question then is there a way to create something similar to the VersionDefinition<V extends Version>
where it enforces you to implement the keys of some interface, data class or map?Brian Dilley
09/28/2020, 8:11 PMwilliam
09/29/2020, 1:54 AM// usage
MyLogger.log("foo")
// impl
inline fun <reified T : Any> T.log(msg: String) {
// ...
val caller = T::class.simpleName
}
CLOVIS
09/29/2020, 12:57 PMVera van Mondfrans
09/29/2020, 2:13 PMabstract class ESGenerics<IDType : DomainID, EntityType : Entity>(
private val elasticsearchClient: RestHighLevelClient,
private val objectMapper: ObjectMapper
) {
// ...
}
All Entity classes has an ID member that should always extend DomainID, so I made this:
interface Entity {
val id: DomainID
}
These functions need EntityType and IDType as types for arguments. Now I feel like I shouldn’t have to pass the IDType to ESGenerics. After all, the EntityType always has an ID field with the correct type. But I can’t figure out how to access the type of EntityType’s ID member in a function declaration. I’d like to rewrite it from:
fun getByIDs(ids: List<IDType>): List<EntityType> {
To:
fun getByIDs(ids: List<EntityType::id>): List<EntityType> {
How can I do that?nanodeath
09/29/2020, 2:50 PMkotlin.test
? I miss AssertJ...Sulav Timsina
09/29/2020, 3:26 PMNir
09/29/2020, 3:56 PMplus
has a single element overload, what's the reason for plusElement existing?cfleming
09/29/2020, 9:03 PMconst val DEBUG = false
and then code like:
if (DEBUG) {
println("Addthread: $thread")
}
If DEBUG
is set to false, will the `println`s be totally compiled out of the class file?BramYeh
09/30/2020, 1:18 AMThiago
09/30/2020, 12:35 PMinternal class CustomInterceptor(
private val processor: Something
) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request())
// FIXME: is this fine? Can this throw Socket timeout?
return runBlocking(Dispatchers.Default) {
processor.suspendUtilHaveAnotherResponseOrThrow(response, chain)
}
}
}
Roland Yeghiazaryan
09/30/2020, 12:54 PMAlign when branches in columns
which is broken for us after the update.
Please see the screenshots for actual and expected behavior.Emmanuel Oga
10/01/2020, 7:40 AMOutputStream
, and some code that needs that data but wants to read from an InputStream
. I came up with this but I was wondering if maybe thre's a more straightforward solution:
/**
* Pipe output to an input stream. Uses a thread to write from output to input.
* See: <https://stackoverflow.com/questions/5778658/how-to-convert-outputstream-to-inputstream>
*/
fun ByteArrayOutputStream.asInputStream(): InputStream = PipedInputStream().also { istream ->
PipedOutputStream(istream).let { ostream ->
Thread { ostream.use { writeTo(ostream) } }.start()
}
}
Thanks!Xabier Gorostidi
10/01/2020, 10:00 AMclass Test(val callbackWork: CustomCallbackWork) : CoroutineScope {
private var job = Job()
override val coroutineContext: CoroutineContext
get() = <http://Dispatchers.IO|Dispatchers.IO> + job
fun start() : Flow<Unit> {
return channelFlow {
launch {
delay(5000)
logger().d("After delay, isActive: $isActive")
close()
}
launch {
callbackWork.apply {
onSuccess = {
offer(Unit)
coroutineContext.cancelChildren()
}
onError = {
offer(Unit)
coroutineContext.cancelChildren()
}
}
}
}
}
}
The log is printed (obviously displaying isActive=true
) after 5 seconds even though onSuccess
is triggered before that delay. However, if I get the reference of the first Job and cancel it below, it works perfectly. What's wrong in the code?Andrea Giuliano
10/01/2020, 12:44 PMKash Kabeya
10/01/2020, 5:19 PMCole K
10/01/2020, 5:56 PMClass.forName("com.mystuff.stylopoc.core.Features.Login")
I think its worth noting that the object, Login, is internal to a sealed class, Features
Any ideas?groostav
10/01/2020, 9:57 PMconciseExpr(listOf("A", "B"), 5) //output: [A, B, A, B, A]
conciseExpr(listOf("A", "B"), 2) //output: [A, B]
conciseExpr(listOf("A", "B"), 1) //output: [A]
you are gaurenteed that the input list is non-empty
so far I'm working with
val output = inputList
.let { partial -> (0 until 1+(inputTargetSize / partial.size)).map { partial }.flatten() }
.take(inputTargetSize)
but i feel like 0 until 1+expr
is cloogyPablo
10/02/2020, 11:54 AMclass Dog(val name: String, val age: Int, val owner:Owner = Owner.Jhon)
Then I have another class that creates that Dog as :
fun getOwner() : Owner {
return if (something is true) Owner.Peter else Owner.Jhon
}
And this is what I'd like to improve, I see that I have this Owner.Jhon
duplicated, because is default value already is there any way to avoid this Owner.Jhon from getOwner?