title: Kotlin equivalent to swift if let? - for class variables?
body: <p>I'm aware of <code>.let {}</code> but the evaluated expression is inside a lambda expression which doesn't work too nice if you need to return something inside a method.</p>
  
  <p><strong>Example problematic code</strong></p>
  
  <pre><code>fun method(): Int {
    if (anyObject != null) {
      val calculatedValue = anObject!!.awesome()
      val magicTrick = calculatedValue + randomMethodName()
  
      return magicTrick
    } 
    return false
  }
  </code></pre>
  
  <p><strong>Is there a better way than this</strong></p>
  
  <pre><code>fun method(): Int {
    val tempObject = anObject
    if (tempObject != null {
      val calculatedValue = tempObject.awesome()
      val magicTrick = calculatedValue + randomMethodName()
  
      return magicTrick
    } else {
      return false
    }
  }
  </code></pre>
  
  <p><strong>Swift equivalent</strong></p>
  
  <pre><code>fun method(): Int {
    if let tempObject = anObject {
      let calculatedValue = tempObject.awesome()
      let magicTrick = calculatedValue + randomMethodName()
  
      return magicTrick
    } else {
      return false
    }
  }
  </code></pre>