ribesg
05/26/2021, 1:49 PMnullableBoolean == true
2️⃣ nullableBoolean ?: falselouiscad
05/26/2021, 1:51 PMribesg
05/26/2021, 1:52 PMnullableList?.contains(x) == true but I usually don’t really know which one to choose in any caseiamthevoid
05/26/2021, 1:53 PMfun Boolean?.safe() { return this ?: false }
But it applicable not everywherelouiscad
05/26/2021, 1:53 PM== true is what the IDE often suggests, but historically, I used ?: falselouiscad
05/26/2021, 1:54 PMribesg
05/26/2021, 1:54 PMiamthevoid
05/26/2021, 1:54 PMfun Boolean?.safe(default: () -> Boolean) { return this ?: default() }
But it almost the same as elvis operatorlouiscad
05/26/2021, 1:55 PMif condition, I think the IDE will suggest == true @ribesgribesg
05/26/2021, 1:55 PMribesg
05/26/2021, 1:56 PMNir
05/26/2021, 1:58 PMNir
05/26/2021, 1:59 PMnullableBoolean == true , but when I look at your case involving a nullable list and ?. I prefer ?: falseNir
05/26/2021, 2:00 PMsomeNullableObject?.memberFunc() ?: default is just a common pattern in Kotlin, generally, so I feel like it is applicable hereelizarov
05/26/2021, 2:06 PMribesg
05/26/2021, 2:07 PMoverride fun hasSourcingRole() =
authTokenService.getTokenRoles()?.contains("ROLE_SOURCING") == true
Maybe coding conventions could cover such case 🙂ribesg
05/26/2021, 2:12 PMNir
05/26/2021, 2:22 PMribesg
05/26/2021, 2:23 PMNir
05/26/2021, 2:23 PMNir
05/26/2021, 2:24 PMribesg
05/26/2021, 2:24 PMNir
05/26/2021, 2:24 PMNir
05/26/2021, 2:25 PMif (foo == true)
vs
if (foo == Tribool.TRUE)Nir
05/26/2021, 2:25 PMribesg
05/26/2021, 2:26 PMif (foo). That’s so much more verbose, like triple the amount of letters 😛ribesg
05/26/2021, 2:27 PMBoolean? in them and it’s perfectly fine for me. For example, we have something where the user can either accept or refuse to consent to something. We store that as a Boolean?, null means we didn’t ask yet. I have no problem with thatribesg
05/26/2021, 2:28 PMnull enough? 😄Nir
05/26/2021, 2:30 PMif (foo) doesn't compileNir
05/26/2021, 2:31 PMNir
05/26/2021, 2:31 PMNir
05/26/2021, 2:31 PMribesg
05/26/2021, 2:44 PMnull cannot mean anything else than “we never got an answer to that question”. I’m not writing forms like it’s the 90's, I’m mutating states and there is no mutator able to set this value to nullNir
05/26/2021, 3:19 PMthanksforallthefish
05/26/2021, 3:29 PMACCEPTED, REFUSED, NOT_ASKED, then in real life I would probably opt for Boolean? 😛 laziness always wins (I always disliked tri-state boolean also when I was mostly coding java, but mostly because in java you never know when something is or is not nullable, in kotlin you do. that small ? makes all the difference in accepting nullable)azabost
05/27/2021, 10:37 AMfun Boolean?.orFalse() = this ?: false
similarly to the existing
@kotlin.internal.InlineOnly
public inline fun <T> List<T>?.orEmpty(): List<T> = this ?: emptyList()louiscad
05/27/2021, 11:00 AM