xii
07/15/2020, 4:35 PMNir
07/15/2020, 5:45 PMBen Woodworth
07/15/2020, 6:56 PMopen class A {
open fun String.x() {
// implementation
}
}
open class B : A() {
override fun String.x() {
// implementation
// 'super' is not an expression, it can not be used as a receiver for extension functions
super.run { this@x.x() }
}
}
Interestingly, when I click on the last x
, IntelliJ highlights the x
function name in A
, and if I remove super.
it'll highlight the x
function name in B
Nir
07/15/2020, 8:54 PMNir
07/15/2020, 9:08 PMclass JsonValue {
constructor()
sealed class JsonData {
class IntWrapper(val x: Int) : JsonData()
class StringWrapper(val x: String) : JsonData()
class ListWrapper(val x: MutableList<JsonValue>) : JsonData()
class ObjectWrapper(val x: MutableMap<String, JsonValue>) : JsonData()
class NullWrapper() : JsonData()
}
var jsonData: JsonData = JsonData.NullWrapper()
companion object {
fun make(x: Int): JsonValue {
val j = JsonValue()
j.jsonData = JsonData.IntWrapper(x)
return j
}
fun make(x: String): JsonValue {
val j = JsonValue()
j.jsonData = JsonData.StringWrapper(x)
return j
}
inline fun <reified T> make(x: List<T>): JsonValue {
val j = JsonValue()
j.jsonData = JsonData.ListWrapper(x.map { JsonValue.make(it) })
return j
}
}
}
So, json is basically a recursive sum type. Sum types in kotlin are typically done via sealed classes, so I'm doing my best with those. I'm trying to have a generic factory function here that works recursively. The problem is, my generic make
that takes a List complains, because the T is not constrained. However, I can only constrain types in Kotlin by interfaces/classes, and I can't add add any new bases/interfaces to types like Int and String, that I want this to work with conveniently. So, is there any nice way to work around this? Or should I basically declare defeat, change the signature to fun make(x: List<JsonValue>)
and put the onus on the user to convert e.g. a List<int>
into a List<JsonValue>
?torres
07/16/2020, 2:18 PMfun <Key:Comparable<Key>, T: IdTable<Key>> T.insertIgnoreAndGetId(body: T.(UpdateBuilder<*>)->Unit) = InsertStatement<EntityID<Key>>(this, isIgnore = true).run {
body(this)
execute(TransactionManager.current())
getOrNull(id)
}
bbaldino
07/16/2020, 3:53 PMKType
?Nir
07/16/2020, 3:58 PMRX
07/16/2020, 8:00 PMCaused by: java.lang.IllegalStateException: Cannot invoke setValue on a background thread
this is my code written on Java (Im new on Android), someone knows why it’s the problem whit my line?ahmad abas
07/16/2020, 11:14 PM<http://gobyexample.com|gobyexample.com>
or <http://elixirschool.com|elixirschool.com>
for kotlin? I usually refer to a short with concise example to get up and running with prog languageallan.conda
07/17/2020, 8:52 AMKlaus
07/17/2020, 10:25 AMsksk
07/17/2020, 12:25 PMnatario1
07/17/2020, 2:19 PMgroupBy { }
, but only group on elements where the key is contiguous?
Say I have a List<Sample>
where sample is class Sample(duration: Int)
.
I need something like a List<List<Sample>>
, where samples are grouped by duration, but not reordered. If durations are 100, 100, 100, 200 and 100, that should be three groups, not two.Jakekudur
07/17/2020, 2:30 PMkenkyee
07/17/2020, 2:51 PMxii
07/17/2020, 5:47 PMTwoClocks
07/17/2020, 7:53 PM(1..100).forEach{ }
but I never reference it
and my linter get's upset w/ me. Is there a better way to do this?voben
07/17/2020, 8:07 PMhybridDeveloper
07/18/2020, 6:20 PMfrank
07/18/2020, 6:39 PM!!
or ?.
in every call.
It's annoying, could be added a feature: Operator that spreads through the members.
Sample:
bob?.department?.head?.name
bob!!.department!!.head!!.name
Something like this: [Edit]
bob.department.head*?.name
bob.department.head*!!.name
@Alexey Belkov [JB] , You know if it is on the Road-MAP or if there is any request for this feature? Or would it not be viable?
Edit:
I'm new with Kotlin but I'm not understand Why this request is so unpopular. Someone to give FeedbackKarlo Lozovina
07/18/2020, 10:27 PMitnoles
07/19/2020, 12:49 AMKroppeb
07/19/2020, 6:21 PMNikky
07/19/2020, 8:21 PMIllegalAccessError
the call is
.addFilter(Query.NumericFilter("price", 0.0, 1000.0))
which is this java code
public Query addFilter(Filter f)
and i think the issue is Filter
which is a private inner class
i don't know if there is something wrong with my code or the library.. is this supposed to work in java ? if so.. why does it break here ?
or why did they write it like that.. if it does not work
just asking if its worth raising a issue over or its a thing related to using kotlin or suchaddamsson
07/20/2020, 11:42 AMseizma
07/20/2020, 2:00 PMimport com.improve_future.harmonica.core.AbstractMigration
import org.jetbrains.exposed.sql.SchemaUtils.create
import org.jetbrains.exposed.sql.SchemaUtils.drop
import org.jetbrains.exposed.sql.Table
object Cities : Table("cities") {
val id = integer("id")
val name = varchar("name", 20)
override val primaryKey = PrimaryKey(id)
}
/**
* Migration
*/
object : AbstractMigration() {
override fun up() {
create(Cities)
}
override fun down() {
drop(Cities)
}
}
but when I try to run harmonicaUp it says
> Task :harmonicaUp FAILED
Task ':harmonicaUp' is not up-to-date because:
Task has not declared any outputs despite executing actions.
:harmonicaUp (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':harmonicaUp'.
> org/jetbrains/kotlin/scripting/repl/GenericReplCompiler
Eugene Freeman
07/20/2020, 4:41 PMinterface RequestsExecutor : Closeable {
suspend fun <T : Any> execute(request: Request<T>): T
}
Is possible to implement ConstantRequestsExecutor
to satisfy the interface and use T parameter on the class level? Thanks
class ConstantRequestsExecutor<T : Any> (
private val responseValue: T
) : RequestsExecutor {
override fun close() {
}
override suspend fun execute(request: Request<T>): T {
return responseValue
}
}
user
07/20/2020, 5:13 PMbbaldino
07/20/2020, 6:37 PMbbaldino
07/20/2020, 6:37 PMstephanmg
07/21/2020, 6:43 AMclass.declaredMemberProperties
Matteo Mirk
07/21/2020, 3:44 PMbbaldino
07/21/2020, 3:46 PMdelcaredMemberProperties
to check for the delegate type. Not sure I'll end up doing this, was just curious if there was any good way available.stephanmg
07/22/2020, 7:15 AMbbaldino
07/22/2020, 3:25 PMstephanmg
07/22/2020, 5:15 PM