One thing I've come to love when using Google Guava's Optional<T> class is the #or() method. Where I can easily get the value in the option OR some other/default value. i.e.
DateTime lastDateTime = (user.getLastLoginDate().or(new DateTime().minusWeek(1))
I was wonder if there was a suitable alternative in Kotlin, nullable types have a #sure() method to get the non-nullable version, I was wondering if it would be good to have something like #or() here as well in Kotlin? Or if there was a preexisting solution?
Given that if is an expression, I was thinking I could just use that, but I’m not sure what I’d put in the if - doing “== null” feels wrong given we have nullable types…