logoalt Hacker News

iamcalledrobyesterday at 3:37 PM1 replyview on HN

I think the ?: operator ends up being a decent alternative, e.g.

  // Swift
  guard let foo = maybeFoo else {
    print("missing foo")
    return false
  }

  // Kotlin
  val foo = maybeFoo ?: run {
    print("missing foo")
    return false
  }
Unless there's a use case for guard I'm not thinking of

Replies

cosmic_cheesetoday at 1:10 AM

It’s a decent alternative, but to someone not familiar with the language what’s going on isn’t as clear.