class WalletManager {

    public Observable<BigDecimal> getTotal() {
        if (mWalletList == null || mWalletList.isEmpty()) {
            return Observable.just(BigDecimal.ZERO);
        }
        return Flowable.fromIterable(mWalletList)
                .map(new Function<Wallet, AccountBalance>() {
                    @Override
                    public AccountBalance apply(Wallet wallet) throws Exception {
                        return wallet.getAccountBalance();
                    }
                }).map(new Function<AccountBalance, BigDecimal>() {

                    @Override
                    public BigDecimal apply(AccountBalance accountBalance) throws Exception {
                        return new BigDecimal(accountBalance.getFree());
                    }
                }).reduce(new BiFunction<BigDecimal, BigDecimal, BigDecimal>() {
                    @Override
                    public BigDecimal apply(BigDecimal balance1, BigDecimal balance2) throws Exception {
                        return balance1.add(balance2);
                    }
                }).toObservable();
    }

    private  WalletManager();

}