rrader
01/31/2018, 3:09 PMjrtapsell
01/31/2018, 4:52 PMShawn
01/31/2018, 6:16 PMgildor
02/01/2018, 8:41 AMnfrankel
02/01/2018, 8:42 AMrequire(geometry is LineString) { "Wrong geometry type in string" }
val line = geometry as LineString
return line
gildor
02/01/2018, 8:44 AMfun String.toGeoLineString(): LineString {
val geometry = readGeometryFromString(this)
return requireNotNull(geometry as? LineString)
}
rCorbellini
02/01/2018, 9:38 AMaeruhxi
02/01/2018, 10:37 AMjakub.dyszkiewicz
02/01/2018, 10:41 AMthenApply
like this is possible
CompletableFuture.completedFuture("x").thenApply { it }
but second version with executor
CompletableFuture.completedFuture("x").thenApply({ it }, Executors.newCachedThreadPool())
throws compilation error and I have to do something like this
CompletableFuture.completedFuture("x").thenApply(java.util.Function<String, String> { it }, Executors.newCachedThreadPool())
fmcauley
02/01/2018, 4:30 PMkevinmost
02/01/2018, 6:02 PM.partition { ... }.let { (first, second) -> first + second }
should work?kevinmost
02/01/2018, 7:29 PMin
keyword can be used in a when
for any operator fun contains
, whether it's defined as String.contains
, List.contains
, your own custom type's contains
function, etcchristoph.pickl
02/02/2018, 5:19 AMdata class Person(
val name: String?,
val age: Int?
)
fun moduleExternal() = Person("", 1)
and a target function with a signature of:
fun safeCall(x1: String, x2: Int) {}
the following WON'T compile due to not being able to smart cast external module's properties:
fun solution_no_smartcasts() {
val person = moduleExternal()
if (person.name != null && person.age != null) {
safeCall(person.name, person.age) // ERROR!
}
}
in order to get rid of the smart cast problem first, i came up with the following idea of destructuring:
fun solution_destructure() {
val (name, age) = moduleExternal()
if (name != null && age != null) {
safeCall(name, age)
}
}
ok, but how about that "low level" if? apple's swift would solve it this way:
if let name = person.name as? String, let age = person.age as? Int {
// name and age are non-optional in here
}
so i thought about an extended if which "kind of" solves it:
fun <T1, T2> ifNotNull(x1: T1?, x2: T2?, action: (T1, T2) -> Unit) {
if (x1 != null && x2 != null) {
action(x1, x2)
}
}
fun solution_kotlin_lets() {
val person = moduleExternal()
ifNotNull(person.name, person.age) { name, age ->
safeCall(name, age)
}
}
what are your thoughts on this topic?gildor
02/02/2018, 9:28 AMpeasee
02/02/2018, 11:50 AMkarelpeeters
02/02/2018, 7:44 PMscrollWindow
value from? @electAthul Antony
02/03/2018, 12:51 PMjrtapsell
02/03/2018, 1:50 PMorg.jetbrains.kotlin:kotlin-stdlib-jre8
has use for AutoCloseable, but org.jetbrains.kotlin:kotlin-stdlib-jdk8
doesn't?sxtanna
02/03/2018, 5:44 PMtoMap()
function available as an extension on a collection of Map.Entry<K, V>
?Shawn
02/04/2018, 9:12 PMList<Int>
and you just want the unique values, use .toSet()
since sets don’t allow duplicate valuesTim
02/04/2018, 10:20 PMjamie-purchase
02/05/2018, 1:59 PMprintln("Hello \$name".contains(Regex("[a-zA-Z0-9]+"))) // true
println("Hello \$name".contains(Regex("\$[a-zA-Z0-9]+"))) // false
have to escape the dollar in the string literal or Kotlin will treat it as a reference
and have to escape the dollar in the pattern or that means end of stringRonnie Magatti
02/05/2018, 2:20 PMedwardwongtl
02/05/2018, 2:35 PMEivind
02/05/2018, 3:05 PMio.ktor.client.HttpClient
and how to handle different return codes 400. Having trouble finding documentation and good examples. Just starting out whit kotlin as well.kevinmost
02/05/2018, 9:33 PMuser
02/06/2018, 3:01 PMkarelpeeters
02/06/2018, 3:09 PMbj0
02/06/2018, 10:20 PMdata class
that has a parameter metadata: List<Item>
, and I'm creating it from a nullable with: metadata?.map { Item(it.key, it.value) } ?: listOf()
. Which is compiling fine, but when metadata is null I'm getting: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull
roamingthings
02/07/2018, 5:15 AM@Entity
@Cacheable(false)
data class Person(
@Id @GeneratedValue
val id: Long? = null,
@NotBlank
val name: String
) {
@OneToMany(mappedBy = "person", cascade = [(CascadeType.ALL)])
var addresses: MutableSet<Address> = HashSet()
}
@Entity
@Cacheable(false)
data class Address(
@Id @GeneratedValue
val id: Long? = null,
@NotBlank val address: String
) {
constructor(address: String, person: Person): this(address = address) {
this.person = person
}
@NotNull
@ManyToOne(optional = false)
lateinit var person: Person
}
roamingthings
02/07/2018, 5:15 AM@Entity
@Cacheable(false)
data class Person(
@Id @GeneratedValue
val id: Long? = null,
@NotBlank
val name: String
) {
@OneToMany(mappedBy = "person", cascade = [(CascadeType.ALL)])
var addresses: MutableSet<Address> = HashSet()
}
@Entity
@Cacheable(false)
data class Address(
@Id @GeneratedValue
val id: Long? = null,
@NotBlank val address: String
) {
constructor(address: String, person: Person): this(address = address) {
this.person = person
}
@NotNull
@ManyToOne(optional = false)
lateinit var person: Person
}
dmulligan
02/14/2018, 5:39 PM