F0X
01/28/2021, 9:48 PMT
being a reified type paramter)?
SomeClass::class.java.isAssignableFrom(T::class.java)
F0X
01/29/2021, 3:42 PMopen val SomeType.someProp: String
, how could I call the super implementation of this when overriding it in a subclass?Daniele B
01/29/2021, 5:25 PMdata class MyObj (
val date : String,
val dailyAmount : Int,
val cumulativeAmount : Int,
)
where cumulativeAmount
is empty
I would like to iterate over that list, and populate cumulativeAmount
with the sum of all dailyAmount
until that date
How to do?Héctor Alpízar
01/30/2021, 4:25 AMVinay Reddy
01/30/2021, 10:23 AMrules_kotlin_version = "legacy-1.3.0"
rules_kotlin_sha = "4fd769fb0db5d3c6240df8a9500515775101964eebdf85a3f9f0511130885fde"
http_archive(
name = "io_bazel_rules_kotlin",
urls = ["<https://github.com/bazelbuild/rules_kotlin/archive/%s.zip>" % rules_kotlin_version],
type = "zip",
strip_prefix = "rules_kotlin-%s" % rules_kotlin_version,
sha256 = rules_kotlin_sha,
)
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories()
kt_register_toolchains()
http_archive(
name = "kt_jvm_grpc",
sha256 = "ccf10e35ba2ff01f594b8fdd4f2ff2426bfd7ec2a676eace4c116e9d4794e49c",
urls = ["<https://github.com/grpc/grpc-kotlin/archive/v1.0.0.tar.gz>"],
)
load("@kt_jvm_grpc//:repositories.bzl", "grpc_kt_repositories")
grpc_kt_repositories()
The error is:
ERROR: error loading package '': Every .bzl file must have a corresponding package, but '@kt_jvm_grpc//:repositories.bzl' does not have one. Please create a BUILD file in the same or any parent directory. Note that this BUILD file does not need to do anything except exist.
This is a public library that I'm simply including. Not sure what to do to fix this error. Would appreciate any help. Thanks!oday
02/01/2021, 2:39 PMclass Solution(object):
def _isValidBSTHelper(self, n, low, high):
if not n:
return True
val = n.val
if ((val > low and val < high) and
self._isValidBSTHelper(n.left, low, n.val) and
self._isValidBSTHelper(n.right, n.val, high)):
return True
return False
def isValidBST(self, n):
return self._isValidBSTHelper(n, float('-inf'), float('inf'))
my attempt produced this
fun isValidChecker(
node: Node<Int>?, low: Int, high: Int
): Boolean {
if (node == null)
return true
val value = node.value
if (value in (low + 1) until high
&& isValidChecker(node.left, low, value)
&& isValidChecker(node.right, value, high)
)
return true
return false
}
fun isValidBST(node: Node<Int>?): Boolean {
return isValidChecker(
node, Int.MIN_VALUE, Int.MAX_VALUE
)
}
oday
02/01/2021, 8:08 PMval map = mutableMapOf<Char, Int>()
map['a'] += 1
Sachin Rana
02/02/2021, 2:10 PMSlackbot
02/02/2021, 11:26 PMStefán Freyr Stefánsson
02/03/2021, 11:07 AMappendText
and appendBytes
but what do I do if I want to append an input stream? There’s copyTo
but that replaces the whole file and I don’t want to read the whole input stream into a byte array (for appendBytes
) because of memory usage. Will I have to handle the buffering myself and write a decorator function (File.appendStream(inputStream: InputStream)
) or does something else exist?supra
02/04/2021, 7:50 AMprivate fun transformDepsRecursively(target: Project, from: Map<*, *>, to: MutableMap<*, *>) {
log.quiet("$TAG transformDepsRecursion start")
from.forEach {
val valueFrom = it.value
var valueTo = valueFrom;
if (valueFrom is ProjectDescriptor) {
valueTo = target.project(valueFrom.path)
} else if (valueFrom is Map<*, *>) {
valueTo = mutableMapOf<String, Any>()
transformDepsRecursively(target, valueFrom, valueTo)
}
mapOf<Any,Any>()
to[it.key]=valueTo
}
log.quiet("$TAG transformDepsRecursion end")
}
oday
02/04/2021, 4:33 PMAllen Eubank
02/04/2021, 5:28 PMCannot use 'T' as reified type parameter. Use a class instead.
. Is there a way to keep `sendMessage/receiveMessage`` in the abstract class? Or do I have to move it into the concrete implementation?poohbar
02/04/2021, 6:31 PM"UMSR65US5BUFE7PS5SNWWKTWU=====".removeSuffix("=")
evaluates to
UMSR65US5BUFE7PS5SNWWKTWU====
what am i missing?Muhammed khaled
02/08/2021, 5:38 AMacoconut
02/08/2021, 2:58 PMSlackbot
02/08/2021, 11:24 PMvineethraj49
02/09/2021, 11:12 AMval foo: String
// foo cannot be used yet
if (cond) {
...
foo = "a"
...
foo can be used here
} else {
...
foo = "b"
...
foo can be used here
}
// foo can be used now
Omar Ayadi
02/11/2021, 2:46 PModay
02/12/2021, 11:29 AMNat Strangerweather
02/13/2021, 4:25 PMAndroidViewModel
so I could pass a context with no memory leak, after this conversation: https://kotlinlang.slack.com/archives/C0B8MA7FA/p1609278349460800?thread_ts=1609277107.460700&cid=C0B8MA7FA
The problem since I've recently updated Kotlin is that this line is highlighted with a leak warning:
private val context = getApplication<Application>().applicationContext
Why this change and what's the point of AndroidViewModel
in that case? Any ideas what I could do to avoid the problem?iona bartishvili
02/14/2021, 6:49 PMRoger Gilliar
02/14/2021, 7:47 PMKy
02/15/2021, 2:53 AMFlow
.
So this works as expected
CoroutineScope(IO).launch {
flow<Int>{
emit(1)
delay(350)
emit(2)
delay(100)
emit(3)
}.debounce(300)
.collect {
Timber.d(it.toString())
}
}
Output: 1, 3
However trying to apply this same idea to a searchview I have..
TextField(
modifier = Modifier
.fillMaxSize()
.background(
color = MaterialTheme.colors
.elevatedSurface(3.dp)
.copy(alpha = 0.95f)
),
value = searchTerm.value, onValueChange = { newValue ->
searchTerm.value = newValue
CoroutineScope(IO).launch {
queryFlow(newValue.text, viewModel)
}
})
This is queryFlow
suspend fun queryFlow(query: String, viewModel: TwitMainViewModel) = flow {
Timber.d("Emitting: ${query}")
emit(query)
delay(500)
}.debounce(1000)
.filterNot {
it.isEmpty()
}
.collect {
Timber.d("MAKING REQUEST FOR: $it")
viewModel.search(it)
}
So in this case, even if I rapid type nnn
a request is made for each; being n
nn
and nnn
. The debounce operator has no effect here. I can’t identify why however, any ideas?
ThanksLewis Diamond
02/15/2021, 4:07 AMprocess.stdin
?Tianyu Zhan
02/15/2021, 4:27 PMDave Trollope
02/15/2021, 9:34 PMvineethraj49
02/17/2021, 1:39 PMpoohbar
02/17/2021, 3:43 PMval block: () -> Any? = ...
is there a difference between calling:
block()
and
block.invoke()
?speed_star
02/18/2021, 3:44 PMEntity
for domain of DDD in Kotlin. Is my field definition correct?
I use val
for id
because this field is immutable. And I use var
for name
and status
because they are mutable fields. All fields are private
to prevent to be updated directly from the outside.speed_star
02/18/2021, 3:44 PMEntity
for domain of DDD in Kotlin. Is my field definition correct?
I use val
for id
because this field is immutable. And I use var
for name
and status
because they are mutable fields. All fields are private
to prevent to be updated directly from the outside.CLOVIS
02/18/2021, 4:07 PMenum
for the status instead of a String
.speed_star
02/18/2021, 4:13 PMMoritz Mücke
02/18/2021, 4:13 PMspeed_star
02/18/2021, 4:17 PMvalue object
. Because data class is the same as the value object
because it is considered the same object if all the fields are the same.
Data class can also be used for Entity
?nanodeath
02/18/2021, 4:57 PMCLOVIS
02/18/2021, 5:16 PMvalue class
is a future syntax, data class
just means “please generate toString
, hashCode
and a few other convenient things (copy
, componentN
...)”. You can still override
those you don't like.speed_star
02/18/2021, 5:36 PMkqr
02/18/2021, 6:07 PM