News for hackers. Stuff that matters.
Re:Learn Kotlin in Y Minutes by seanalltogether on Thursday May 18, 2017 @02:06PM (#14369568)
Does it have an equivalent to Swifts if let clause?

    if let person = selection?.organization?.owner {
        setTitle(person.name)
        setImage(person.image)
    }
Re:Learn Kotlin in Y Minutes by asadmshah on Thursday May 18, 2017 @02:20PM (#14369675)
Yes.

    val person = selection?.organization?.owner?.let {
        setTitle(it.name)
        setImage(it.image)
        it
    }
Re:Learn Kotlin in Y Minutes by amatheus on Thursday May 18, 2017 @02:55PM (#14369987)
You may use `also`. It is like let but it returns the receiver.

    val person = selection?.organization?.owner?.also {
        setTitle(it.name)
        setImage(it.image)        
    }
Re:Learn Kotlin in Y Minutes by metroidfan832 on Thursday May 18, 2017 @02:37PM (#14369831)
You can use `also` instead of `let` to remove the last `it` line.
Re:Learn Kotlin in Y Minutes by seanalltogether on Thursday May 18, 2017 @03:28PM (#14370304)
ok so I'm guessing you can't operate on more then one scope at once?

    if let person1 = dashboard?.owner, person2 = selection?.organization?.owner {
    	person1.cloneProperties(person2)
    }
Re:Learn Kotlin in Y Minutes by kodablah on Thursday May 18, 2017 @03:45PM (#14370450)
You'd use nested let clauses and name the param instead of using the implicit "it"
Re:Learn Kotlin in Y Minutes by meddlepal on Thursday May 18, 2017 @04:05PM (#14370647)
Or just write a function to accomplish the same behavior: http://stackoverflow.com/a/35522422/364135

Would be nice if there was a multiLet in the stdlib. Probably something that happens eventually anyways.

Re:Learn Kotlin in Y Minutes by ionforce on Thursday May 18, 2017 @02:34PM (#14369805)
Is this setting a value to the name `person`? What is the value?
Re:Learn Kotlin in Y Minutes by heifer2822 on Friday May 19, 2017 @04:51AM (#14373874)
selection?.organization?.owner is an optional value, meaning it might be nil/null. That "if let" basically says if it's not nil to assign its value to "person" and execute the block. Then inside the block you can treat "person" as a non-optional, known value.