Tuang
09/25/2019, 8:58 AMhandler: (key: K) -> V?)
means
In the following function
fun getOrPut(key: String, handler: (key: String) -> V?)
i thinks handler
is something likes the arguments name, so what are the rest?
is it a lambda ?Sylvain Patenaude
09/25/2019, 6:59 PMKenneth
09/26/2019, 10:42 AMCharacter.getNumericValue()
?Martin Nordholts
09/26/2019, 1:05 PMval foo="bar"
I would like to not have to write the foo=
part in "foo=$foo"
in order to get the string foo=bar
, but, like in Python, perhaps like this instead: "${foo=}"
but that gives me compilation errors in Kotlin version 1.3.41 (JRE 1.8.0_221-b11)Shawn
09/26/2019, 9:01 PMSylvain Patenaude
09/26/2019, 9:04 PMJosh Taylor
09/27/2019, 12:27 AMursus
09/27/2019, 2:38 AMtake
but that creates a new listursus
09/27/2019, 2:42 AMursus
09/27/2019, 3:41 AMandym
09/27/2019, 3:01 PMTuang
09/29/2019, 4:17 AMimport java.time.Duratio
class SimpleObjectCache (val cacheDuration: Duration) {
private val cacheManager = if (cacheDuration.getSeconds().toInt() <= 2147483647) SimpleObjectCacheManager(cacheDuration.getSeconds().toInt()) else throw IllegalArgumentException("cacheDuration Int value is out of range")
It is simple, i hope you got what i m doing is.
cacheManger
is too long right? 😁
Is there any better way? 🤔Vague
09/30/2019, 10:32 AMRick Pendrick
09/30/2019, 3:00 PMfun String.asIndex(): Int = withIndex().sumBy { ... }
Why does the call to withIndex() not need use "it" or "this" ? <<I am newbie, obviously!>>Rick Pendrick
09/30/2019, 3:00 PMskendrick
09/30/2019, 3:39 PMstr1 = "ABC"
str2 = "ABB"
diff = 1
// JS
str1.reduce((accumulator, currLetter, index) => {
if (currLetter !== str2[index]) return accumulator + 1
}, 0)
Is this a kotlin-y way to approach the problem or am I being a dingus?Ellen Spertus
09/30/2019, 9:06 PMserebit
09/30/2019, 9:07 PMvinny2020
09/30/2019, 9:28 PMVinicius Araujo
09/30/2019, 10:03 PMfun StringValues.getUuidParam(name: String): UUID {
val id = getAll(name)?.firstOrNull()
if(id != null)
try {
return UUID.fromString(id)
} catch (e: InvalidArgumentException) {
httpException(developerMessage = "Parameter $name does not contain a valid UUID")
}
else
httpException(developerMessage = "Required param $name is not present")
}
Viet Hoang
10/01/2019, 8:18 AMfun String?.whenNotNullOrEmpty(callback: (String) -> String?): String? {
return if (this.isNullOrEmpty()) null
else callback(this)
}
but this doesn’t ?
fun String?.whenNotNullOrEmpty(callback: (String) -> String?): String? {
return if (isNullOrEmpty()) null
else callback(this)
}
Colton Idle
10/02/2019, 3:02 AMif (viewModel.value?.items()?.subItems != null) {
//Do my thing
}
I don't think this is bad because it's straight forward. As long as that statement is not null I want to execute some code. Is there a more idiomatic way of doing this?Ellen Spertus
10/02/2019, 6:18 PMclass NearbyConnection{
var connectionsClient: ConnectionsClient = Nearby.getConnectionsClient(context)
public sealed class ConnectionState(val name: String) {
inner class Authenticating: ConnectionState("authenticating") {
fun accept() {
connectionsClient.acceptConnection(neighborId, payloadCallback)
updateState(ConnectionState.Connecting(neighborId, neighborName))
}
}
I am getting the error “unresolved reference connectionsClient” within the function.Prajjawal Banati
10/03/2019, 7:19 AMEllen Spertus
10/03/2019, 7:21 PMConnectionState
). Here’s my code:
public sealed class ConnectionState() {
var name = ConnectionState::class.simpleName ?: "null"
object Isolated : ConnectionState()
object Advertising : ConnectionState()
object Discovering : ConnectionState()
}
Any advice?Slackbot
10/04/2019, 6:40 AMFlorian
10/04/2019, 8:25 AMFlorian
10/04/2019, 2:44 PMval a
get() = Random().nextInt(10)
Is this the only situation a val
can return a different value each time it is accessed? (obviously the Random function is replaceable)Florian
10/04/2019, 2:57 PMFlorian
10/04/2019, 7:01 PMconst
as a standalone keyword instead of const val
? There is no other const
combination as far as I see itFlorian
10/04/2019, 7:01 PMconst
as a standalone keyword instead of const val
? There is no other const
combination as far as I see itKirill Zhukov
10/04/2019, 7:35 PMconst
, and can’t assign function results.const
?Florian
10/04/2019, 7:40 PMKirill Zhukov
10/04/2019, 7:51 PMconst
is a modifier in this case, where as val
is a keyword. val
indicates a value that cannot be reassigned and by default it’s assigned in runtime.const
is a modifier to a val
keyword, it says how the value is being assigned.class
keyword and private
modifierprivateClass
keyword (since we have functions and other things) would be redundant, if it makes senseconst
is more flexible this wayFlorian
10/04/2019, 7:55 PMKirill Zhukov
10/04/2019, 7:58 PMconst
modifier on functionsFlorian
10/04/2019, 8:00 PMconst
can't be used somewhere else, or can it?Kirill Zhukov
10/04/2019, 8:00 PMFlorian
10/04/2019, 8:05 PMilya.gorbunov
10/04/2019, 8:56 PMconst
is a soft keyword, that means it can be used in other places just as a usual identifier, e.g.
val const = kotlin.random.Random.nextInt()
println(const)
Kirill Zhukov
10/04/2019, 9:02 PMFlorian
10/04/2019, 9:46 PMarekolek
10/05/2019, 10:01 AM