Conditions in Data class Kotlin

so, I heard there are no ternary operators in kotlin, so, how can I achieve the following in kotlin data class

JS

 {online.map(function(item){
     
         return (
          <div key={item.uid} >

  {item.Gender== 'Male' ?
          
          <li >

<div><img src={item.photoURL}/><p><b>{item.displayName}</b></p></div>
    </li>
         
: null}
                   
          </div>
    )
    })}

online is an object that contains the list of user information
{item.Gender === 'Male' ? checks and returns only users that are male

so, can that similar feature be achieved in Kotlin?

Kotlin data class

data class UserInfo(
    val uid: Uids) {
        data class Uids (
    var Gender: String? = null,
    var uid: String? = null,
    var displayName: String? = null,
    var photoURL: String? = null)
}

would the conditions be placed in the adapter, in the fragment class containing the recyclerView, or in the class that is populating the data class? and how would it be done?

Source: Android Questions

LEAVE A COMMENT