Hexa
11/25/2018, 12:42 PMif(!item.name.isNullOrEmpty()){
itemMap["name"] = AttributeValue().withS(item.name)
}
Tolriq
11/25/2018, 12:45 PMitem.name?.takeif { it.isNotEmpty() }?.let { AttributeValue().withS(it) }
Hexa
11/25/2018, 12:47 PMtakeif
functionhallvard
11/25/2018, 12:48 PMisNotNullOrEmpty()
is that you get more checks into one, and yet the semantics of it is very clear to the human eye.Hexa
11/25/2018, 12:49 PMTolriq
11/25/2018, 12:50 PMhallvard
11/25/2018, 12:52 PMtakeIf
is very useful.Tolriq
11/25/2018, 12:58 PMHexa
11/25/2018, 1:05 PMTolriq
11/25/2018, 1:07 PMclass Item(var name: String? = null)
val item = Item()
fun test() {
if (!item.name.isNullOrEmpty()) {
var t: String = item.name
}
}
That does not work compiler will complain that item.name is mutable and can't be smartcast 😉