Yusuf.I
08/23/2022, 2:47 PMYusuf.I
08/23/2022, 2:49 PMYusuf.I
08/23/2022, 2:50 PMBen Edwards
08/23/2022, 3:54 PMSiddhartha Juluru
08/23/2022, 10:10 PMHassaan
08/24/2022, 10:43 AMOleg Shuliak
08/24/2022, 2:51 PMprivate fun convertToEmployeeData(response: ListEmployeesResponse): List<EmployeeData> {
val employeeDataList = mutableListOf<EmployeeData>()
response.dataList.forEach { data ->
val employeeData = EmployeeData(data.employeeId)
data.attributesList.forEach { attributeValue ->
when (attributeValue.attributeId) {
FIRST_NAME -> employeeData.firstName = attributeValue.stringValue?.toString()
LAST_NAME -> employeeData.lastName = attributeValue.stringValue?.toString()
}
}
employeeDataList.add(employeeData)
}
return employeeDataList
}
it works, but I’m not sure if using forEach
twice is the best approach here.
Any suggestions?Xiang Rong LIn
08/24/2022, 5:31 PMAyfri
08/25/2022, 3:49 AMtypealias <T>
for Pair<T, T>
?Phani Mahesh
08/25/2022, 5:16 AMallan.conda
08/25/2022, 7:05 AMtoString
to the value? We’ve had issues where wrapping a primitive to an inline class requires checking all usages of it specially when the primitive value is already being passed directly as a String.
Wondering if anyone is doing it by default.Elizeu Silva dos Santos
08/26/2022, 11:46 AMfun Route.customerRouting().
It means I am “injecting” customerRouting()
function into Route
class? Also, what is exactly the second parameter of this function: public fun Route.route(path: String, build: Route.() -> Unit)
. I am a java developer and some aspects of kotlin are a bit weird for mejeggy
08/26/2022, 1:43 PMcopy
function on a generic type? I would like to change the generic type of T
to make sure that it's a data class
. Or is this just impossible?
fun <T: Any> doCopy(dataObject: T): T {
return dataObject.copy()
}
Hassaan
08/26/2022, 5:24 PMCJ Lindblad
08/26/2022, 7:57 PMwhen (someValue) {
in list1 && in list2 -> TODO()
}
Or do I have to write it like this?
when {
someValue in list1 && someValue in list2 -> TODO()
}
Tobias Hermann
08/27/2022, 6:07 AMtuplize
function:
fun foo(x: Int, y: Int) = 3 * x + 2 * y + 1
fun <T, U, R> tuplize(f: (T, U) -> R): ((Pair<T, U>) -> R) = { (a, b): Pair<T, U> -> f(a, b) }
val xs = listOf(Pair(1, 2), Pair(42, 23))
val ys = xs.map(tuplize(::foo))
It works, but I guess arrow-kt already has something nice build-in, and I just can't find it. Can somebody help me out?Hassaan
08/27/2022, 3:36 PMNelsonC
08/28/2022, 7:27 PMBernhard
08/30/2022, 9:32 AMbinarynoise
08/30/2022, 12:01 PMLukasz Kalnik
08/30/2022, 2:38 PMIterable.all
returning true
when called on an empty List:
val list = emptyList<Boolean>()
list.all { it } // true
list.none { it } // true
list.any {it } // false
Ellen Spertus
08/30/2022, 6:30 PMprint()
and println()
that can be called statically without a prior import
?zt
08/31/2022, 3:34 AMPath
sorted such that files/folders prefixed with a .
are first, then alphabetically, and also so all folders come before files? I'm not really familiar with the sorting methods available to collections.Slackbot
08/31/2022, 6:53 AMalthaf
08/31/2022, 4:14 PMoverride suspend fun isLoginSessionValid(): Flow<Result<Boolean>> = flow {
ParseUser.getCurrentUser()?.let { parseUser ->
if (!parseUser.isAuthenticated)
cleanupOnLogout()
emit(Result.success(parseUser.isAuthenticated))
} ?: kotlin.run {
cleanupOnLogout()
emit(Result.success(false))
}
}
Jasmin Fajkic
08/31/2022, 5:29 PMLandry Norris
08/31/2022, 8:34 PMfun foo(x: Int) = myWrapper {
doSomething();
}
where the wrapper function has a signature like
fun <T> myWrapper(() -> T): T
This works well for most cases except where I want foo to return Unit and doSomething() has a return type. In this case, I have to change the sample to
fun foo(x: Int) = myWrapper {
doSomething();
Unit //return Unit
}
Is there a way to tell the compiler that if the function foo has a return type of Unit, it should ignore the value returned by doSomething(), and treat it like a normal statement, similar to if I didn’t have my wrapper?Hassaan
09/01/2022, 11:03 AMreadLine().toBoolean() returns a Boolean type
and
readLine().toInt() throws a compile type error
Tech
09/01/2022, 12:07 PMNothing
to a reified type, or something similar?Kenneth
09/01/2022, 1:15 PM