title: Kotlin How to use java streams .map() in kotlin to map a different object response
body: <p>I am trying to map an array of objects to another array with different kind of objects, I used to do this using streams in java 8 it was pretty straight forward, instantiate an object set its values and return the object. I just switched to Kotlin and really sometimes is more confusing to do this kind of operations. All the examples I found are really simple and could not find something I want.</p>
  
  <p>I have this BalanceMap class:</p>
  
  <p><code>data class BalanceMap @JsonCreator constructor(
          var balType: String,
          var value: Any
  )</code></p>
  
  <p>I am getting the data from web service.</p>
  
  <pre><code>val balances: List&lt;AcctBal&gt; = res.getAcctBals();
  </code></pre>
  
  <p>the AcctBal class looks like this</p>
  
  <pre><code>public class AcctBal {
  
    @SerializedName("CurAmt")
    @Expose
    private CurAmt curAmt;
  
    @SerializedName("Desc")
    @Expose
    private String desc;
  
    @SerializedName("ExpDt")
    @Expose
    private LocalDateTime expDt;
  }
  </code></pre>
  
  <p>and try to map that response to <code>var balanceList: List&lt;BalanceMap&gt;</code></p>
  
  <pre><code>balances.map {}
  </code></pre>
  
  <p>--> <code>var balanceList: List&lt;BalanceMap&gt; = balances.map { t -&gt; fun AcctBal.toBalanceMap() = BalanceMap(
                  balType = "",
                  value = ""
          )}</code></p>
  
  <p>I want to do something like this:</p>
  
  <pre><code>List&lt;ProductDetail&gt; details = acctBal.stream().filter(f -&gt; f.getBalType() != null).map(e -&gt; {
                  String bal = e.getBalType();
                  if (avalProductInfo.getBankId().equals("00010016")) {
                      bal = e.getBalType();
                  }
                  ProductDetail detail = new ProductDetail();
                  detail.setItem(bal);
                  if (e.getCurAmt() != null) {
                      detail.setValue(e.getCurAmt().getAmt().toString());
                  } else if (e.getRelationDt() != null) {
                      detail.setValue(e.getRelationDt().toGregorianCalendar().getTimeInMillis());
                  } else if (e.getMemo() != null) {
                      detail.setValue(e.getMemo());
                  }
                  return detail;
              }).collect(toList());
  </code></pre>
  
  <p>I've been experimenting but is always wrong, any help will be highly appreciated. Happy coding!</p>