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.
I have this BalanceMap class:
data class BalanceMap @JsonCreator constructor(
        var balType: String,
        var value: Any
)
I am getting the data from web service.
val balances: List<AcctBal> = res.getAcctBals();
the AcctBal class looks like this
public class AcctBal {
  @SerializedName("CurAmt")
  @Expose
  private CurAmt curAmt;
  @SerializedName("Desc")
  @Expose
  private String desc;
  @SerializedName("ExpDt")
  @Expose
  private LocalDateTime expDt;
}
and try to map that response to var balanceList: List<BalanceMap>
balances.map {}
--> var balanceList: List<BalanceMap> = balances.map { t -> fun AcctBal.toBalanceMap() = BalanceMap(
                balType = "",
                value = ""
        )}
I want to do something like this:
List<ProductDetail> details = acctBal.stream().filter(f -> f.getBalType() != null).map(e -> {
                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());
I've been experimenting but is always wrong, any help will be highly appreciated. Happy coding!