ivano
01/11/2020, 9:15 PMgetRecipes
in a lambda?Animesh Sahu
01/12/2020, 11:47 AMAnimesh Sahu
01/12/2020, 12:33 PMtipsy
01/12/2020, 2:55 PMandyg
01/12/2020, 6:15 PMget
the first of a list of possible keys from a map -- for example if the keys might not always be exact: personMap.getFrom("lastname", "LastName", "last_name", "nameLast")
?A
01/12/2020, 7:50 PMvar name=<lambda>
is declared in a class, its returning value can be modified for a particular instance?This instance can be passed on to other functions which would end up with wrong data. I thought kotlin lambdas are supposed to be a clean looking replacement for functions, but functions do not change their logics. For eg:Arkadii Ivanov
01/13/2020, 12:08 PMby
keyword and make all the delegated methods final
. My use case is as follows:
interface MyInterface {
fun doSomething()
}
internal class MyInterfaceImpl : MyInterface {
override fun doSomething() {
// Do something here
}
}
abstract class MyClass : MyInterface by MyInterfaceImpl() {
abstract fun doSomethingElse()
}
class MyClassImpl : MyClass() {
override fun doSomethingElse() {
// Do something here
}
override fun doSomething() {
// This override should be forbidden
super.doSomething()
}
}
Jukka Siivonen
01/13/2020, 12:53 PMdata class Application(val applicantName: String?, val dateOfBirth: LocalDate?, val status: ApplicationStatus)
CFrei
01/13/2020, 2:46 PMCzar
01/13/2020, 2:48 PMsealed class A
class X : A()
class Y : A()
class Z : A()
From what I've seen usually people do this to be able to write something like
class Service {
fun returnSomething(a: A) = when(a) {
is X -> /* ... */
is Y -> /* ... */
is Z -> /* ... */
}
}
Isn't it an illustration of an OOP anti-pattern, though?
Shouldn't it have been something along the lines of:
Service {
fun returnSomething(a: A) = a.returnSomething()
}
Anytime you find yourself writing code of the form "if the object is of type, then do something, but if it's of typeT1
, then do something else," slap yourself!T2
— Scott Meyers, Effective C++
Jan Shair
01/13/2020, 4:24 PMSandy
01/13/2020, 9:32 PMIaroslav Postovalov
01/14/2020, 1:25 PMDominaezzz
01/14/2020, 2:26 PMfun <T> List<T>.idk(): List<T> = TODO()
fun <T> List<T>?.idk(): List<T>? = TODO()
fun lol() {
val real: List<String> = emptyList()
val empty: List<String>? = emptyList()
real.idk() // Resolves the first function.
empty.idk() // Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type List<String>?
}
(Sorry about the names, they take up too much time to come up with)
This only happens when the receiver is generic. The functions resolve as expected for String
.dave08
01/14/2020, 3:01 PMelapsedNow()
from a time point that I receive from an api...bod
01/14/2020, 5:38 PMfooBar(a: Int? = null, b: String? = null, c: String? = null)
where actually either a, b or c should be non null. Is there an idiomatic way to do this? I think Sealed classes would work, but a bit cumbersome. I've also seen people talking about an Either type (there's one in Arrow). Thoughts?taer
01/14/2020, 7:10 PM<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
</dependency>
Same with kotlin-reflect(which I belive should be scope of reflect
). Is this intentional or an oversight?magisu
01/14/2020, 11:00 PMiex
01/15/2020, 3:22 PMNikky
01/15/2020, 5:51 PMAlexjok
01/16/2020, 8:50 AMSlackbot
01/16/2020, 9:45 AMaddamsson
01/16/2020, 9:46 AMubu
01/16/2020, 12:15 PMtypealias Id = String
Thanks!iex
01/16/2020, 1:56 PMprotocol ChildViewController where Self: UIViewController { // <--ChildViewController is "interface" and it's constrained to a specific class
func foo()
}
extension ChildViewController {
func foo() { <-- this is basically default interface implementation
print(self.view) <-- here we access a field of the concrete type, i.e. UIViewController
}
}
gian
01/16/2020, 3:45 PM.not()
instead of !
?Vitali Plagov
01/16/2020, 4:10 PMMaHDi
01/16/2020, 4:49 PMfun main(args: Array<String>) {
var line = readLine()
while (line !=null) {
println(line)
line = readLine()
}
println("this line")
}
Gregor Zeitlinger
01/16/2020, 4:58 PMSylvain Patenaude
01/16/2020, 5:44 PMSylvain Patenaude
01/16/2020, 5:44 PMCasey Brooks
01/16/2020, 5:48 PM@file:JvmName("Name3")
to change the name of the generated class for the top-level functions https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#package-level-functionsSylvain Patenaude
01/23/2020, 9:16 PM@file:JvmName("Name3")
for iOS or should I go back to putting my functions in an object
named "Name3"?object
named "MyObject" for instance, a call from iOS (Swift for instance) would look like this:
MyObject*Kt*.function()@file:JvmName("CustomName")
for iOS. Now when documenting my SDK, I need 2 different APIs for Android and iOS:
• Android: MyObjectName.someFunction()
• iOS: MyObjectName*Kt*.someFunction()
This is really annoying.