Hullaballoonatic
06/01/2019, 10:08 PMHullaballoonatic
06/02/2019, 5:43 PMfun foo() = true
be referenced as such:
val bar: () -> Boolean = foo
?
or conversely:
interface Foo {
val bar: () -> Boolean
}
object Bar : Foo {
override fun bar() = true // nope. why not?
override val bar = { true } // yep
}
Florian
06/02/2019, 9:20 PMsjthn
06/03/2019, 5:59 PMfun fetchProducts(): Result<List<Product>> { }
IDE is erroring "kotlin.Result cannot be used as a return type"Hullaballoonatic
06/03/2019, 9:00 PMvar foo = 1
private set(v) {
field = v
}
Vague
06/04/2019, 1:47 PMCompanion Object
and using an Object Declaration
?karelpeeters
06/05/2019, 8:43 AMv.row(j) *= -1
which will pick the correct overload.karelpeeters
06/05/2019, 5:39 PMcols
with an operator fun set
and you can do M.cols[3] = v
.Hullaballoonatic
06/05/2019, 7:53 PMinterface Foo {
val a: Int
val b: Int
fun sum() = a + b
}
fun Foo(a: Int, b: Int) = object : Foo {
override val a = a
override val b = b
}
is it more expensive to instantiate object literals than class instances?Hullaballoonatic
06/05/2019, 7:54 PMList
and MutableList
and the like are written in stdlibSaku Ytti
06/06/2019, 9:35 AMKen McDonald
06/06/2019, 2:18 PMSeb C
06/06/2019, 4:42 PMSeb C
06/07/2019, 12:09 AMHullaballoonatic
06/07/2019, 9:22 PMfun foo(values: DoubleArray) = //do the things
fun foo(vararg values: Double) = foo(DoubleArray(values.size) { values[it] })
fun foo(values: List<Double>) = foo(values.toDoubleArray())
fun foo(values: Vector) = foo(values.toDoubleArray())
I can use extension methods and chuck many of them into separate files, but sometimes I can't, like in the case of inner classes or objects.
is there a better way that i'm not really seeing? afaik there is absolutely no shared parent class between arrays and lists. my Vector
class at least shares Iterable<Double>
with List<Double>
, but in many cases it's more efficient to duplicate the body of functions the two share instead of unifying them under Iterable
because most methods require Iterable::toList
before I can do foo
things to it.Hullaballoonatic
06/07/2019, 9:56 PMMike
06/08/2019, 12:44 AMclass MyTests : FunSpec({
context("a test group") {
test("String length should return the length of the string") {
"sammy".length shouldBe 5
"".length shouldBe 0
}
}
})
What would be the purpose of this? Is this a kotlin thing? Or a kotlin test thing. It turns out googling for “kotlintest context” or “kotlin context” doesn’t find much that appears relevant.Guru
06/08/2019, 8:02 AMPeter Kehl
06/09/2019, 12:44 AMclass Foo { lateinit var i: Integer }
var foo= Foo()
foo.i.isInitialized // =>
// error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
// @SinceKotlin @InlineOnly public val @receiver:AccessibleLateinitPropertyLiteral KProperty0<*>.isInitialized: Boolean defined in kotlin
foo::i.isInitialized // ->error: backing field of 'var i: Integer' is not accessible at this point
Help, please.chan
06/10/2019, 5:44 AMabstract class Function<
TDatabase : Database<*, *>,
TSchema : Schema<*, *, *>
>(
jdbc: JdbcTemplate,
database: TDatabase,
schema: TSchema,
name: String
) : SchemaObject<TDatabase, TSchema>(jdbc, database, schema, name) {
open val args: Array<String> = emptyArray()
override fun toString(): String {
return super.toString() + "(" + Strings.arrayToCommaDelimitedString(args) + ")"
}
}
Hullaballoonatic
06/10/2019, 6:39 PMclass Foo(val title: String = *the name of the field storing the instance of this class*)
val foo = Foo()
So, in this case "foo"bjonnh
06/11/2019, 6:03 PMscottiedog45
06/12/2019, 11:06 AMvar phoneOrTablet : String = Resources.getSystem().getBoolean(R.bool.isTablet) ? "Tablet" : "Phone"
spand
06/12/2019, 11:07 AM? :
in kotlinpoohbar
06/12/2019, 2:31 PMas
and as?
..
In this example ref as? String
the result is null
if the ref
is not a String
or if the ref
is null, correct?
I need to cast a reference to String and throw if it is not a String. How can I do that?scottiedog45
06/13/2019, 10:40 AMMarko Mitic
06/13/2019, 11:22 AMclass C: Iface by Delegate(this)
Slackbot
06/13/2019, 12:35 PMbjonnh
06/13/2019, 5:49 PMHullaballoonatic
06/13/2019, 9:38 PMfun <F: Foo> foo1(fooRef: KProperty1<Bar, Foo>) = ...
fun <F: Foo> foo2(foo: Foo) = foo1(WHAT GOES HERE?)
Is there a simple way to do this? Bar::(something with foo)
?Hullaballoonatic
06/13/2019, 9:38 PMfun <F: Foo> foo1(fooRef: KProperty1<Bar, Foo>) = ...
fun <F: Foo> foo2(foo: Foo) = foo1(WHAT GOES HERE?)
Is there a simple way to do this? Bar::(something with foo)
?karelpeeters
06/13/2019, 10:23 PMfoo1
takes a property of Bar
with type Foo
, and all you've got is an instance or Foo
. How could that possibly converted to the latter?Hullaballoonatic
06/13/2019, 10:27 PMfooRef: KProperty1<Bar, String>
, e.g. Bar::name
. How could you engineer KProperty1<Bar, String>
from name
?karelpeeters
06/13/2019, 10:31 PMclass Bar(val name: String)
and then I do foo2(bar.name)
there's no connection to bar
anymore, bar.name
is just an ordinary String
instance out there with everything elsefoo("test")
, it may be a "property" of multiple classes, it may be in a list somewhere, ...Hullaballoonatic
06/13/2019, 10:32 PMBar
part yourself again.karelpeeters
06/13/2019, 10:33 PM