Jérémy CROS
03/09/2021, 3:46 PMval result = withTimeoutOrNull(10000L) {
flowProvider.getFlow().collect {
if (it.condition) // ALL GOOD, can exit collect and keep going
else // Not good enough, collect some more and see if I can get a match
}
}
if (result) == null // Assume nothing was collected?
Is it even feasible this way?groostav
03/09/2021, 11:47 PMCollection<A> op Collection<B> -> Collection<Serializable>
as suspicious?Denis Ambatenne
03/10/2021, 8:36 AMmatt
03/10/2021, 11:33 AMVampire
03/10/2021, 12:46 PMfind(input, 50)
to search after character 50 but so that only until character 50 is tried to match.
And what is the difference between slice
, substring
and subSequence
?Gopal S Akshintala
03/10/2021, 1:19 PMManuel Pérez Alcolea
03/10/2021, 7:46 PMclass Vector(val x: Double, val y: Double, val z: Double = .0) {
operator fun div(n: Double) =
Vector(x / n, y / n, z / n)
fun magnitude() = sqrt(x*x + y*y + z*z)
fun normalized() = when (val m = magnitude()) {
0.0 -> Vector(x, y, z)
else -> this / m
}
// more stuff
}
and I want to have another class with most of the same functionality, but more like as a wrapper, where x
and y
are Int
but everything else is computed with `Double`s, and with 2 additional Int
properties targetX
and targetY
. Is there anything in Kotlin that can help me achieve this without writing every method that wraps another method? (or any good idea?) I tried using`by` with an interface to delegate but the types (Int
and Double
) wouldn't match so it wouldn't work.Luiz Carlos Arruda Silva
03/10/2021, 9:43 PMhttps://www.youtube.com/watch?v=4E4v6nEehE0▾
dany giguere
03/11/2021, 12:48 AMursus
03/11/2021, 4:13 AMfoo(), getFoo(), loadFoo(), findFoo()
?crummy
03/11/2021, 4:34 AMval c = Array<Int>::class
I want to get the parameterized type of c (i.e. Int
). Is this possible on the JVM?elect
03/11/2021, 7:23 AMg
in a string such as v0.1.9-1-g3a259e0
(which is always "$version-g$commitId") other than using something relying on lastIndexOf(-g)
and then combining the two substrings?Eugen Martynov
03/11/2021, 9:28 AM.kotlin_module
files are used? I can not open it in IDE unfrotunatelyPaul Woitaschek
03/11/2021, 1:32 PMMarc Knaup
03/11/2021, 3:59 PM0
to a Double
? Why 0.0
?Manuel Dupont
03/11/2021, 5:02 PMRalph Nader
03/11/2021, 6:38 PMLuigi Scarminio
03/11/2021, 10:33 PMPeter Ertl
03/12/2021, 9:03 AMYan Pujante
03/12/2021, 6:19 PMJason Jackson
03/12/2021, 10:43 PMpavi2410
03/13/2021, 6:28 PMfn factorial(n: u32) -> u32 {
if dbg!(n <= 1) {
dbg!(1)
} else {
dbg!(n * factorial(n - 1))
}
}
I hope to be able to write something like this in Kotlin
fun factorial(n: Int): Int {
if (dbg(n <= 1)) {
return dbg(1)
} else {
return dbg(n * factorial (n - 1))
}
}
Possible incomplete implementation
fun <T> dbg(expr: T): T {
println(expr)
return expr
}
Is there any way to capture the expression syntax itself rather than the value?Vampire
03/13/2021, 8:49 PMFunction1
but as consumer, so without return value?Ch8n
03/14/2021, 8:32 AMelementAt()
function on collections, I started to wonder which one is better for getting values, elementAt()
or get()
.. Found only this line element at is useful for collections that do not provide indexed access, or are not statically known to provide one.
, so does that mean elementAt()
is useful for non-index-based collection? like LinkedList? maps? graphs? Even examples show https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/element-at.html arrays and List sample not other once.. is it because there is only list, set, and map in collections of Kotlin?v79
03/14/2021, 9:52 AMuser
03/14/2021, 2:03 PMbjonnh
03/14/2021, 8:44 PMException in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class net.nprod.bcm.separation.PeakSimulatorKt (in module bcm) cannot access class smile.math.special.Erf (in unnamed module @0x4993dace) because module bcm does not read unnamed module @0x4993dace
Ralph Nader
03/14/2021, 9:40 PMnkiesel
03/15/2021, 5:11 PMfun <T> List<T>.replaceOrAdd1(item: T, predicate: (T) -> Boolean): List<T> { ... }
fun <T> List<T>.replaceOrAdd2(item: T, predicate: (T) -> Boolean): List<T> { ... }
data class Person(val name: String, val age: Int, val email: String, val address: String = "")
val listOfProposals = listOf(
fun(list: List<Person>, person: Person, predicate: (Person) -> Boolean) = list.replaceOrAdd1(person, predicate),
fun(list: List<Person>, person: Person, predicate: (Person) -> Boolean) = list.replaceOrAdd2(person, predicate),
)
// <https://pl.kotl.in/GvbQWnFEq> is the link to the working example
xii
03/15/2021, 7:06 PMxii
03/15/2021, 7:06 PM