https://kotlinlang.org logo
Title
d

dh44t

01/24/2018, 3:18 PM
unless someone has a better idea
z

ziggy42

01/24/2018, 3:24 PM
So you would
var total = getTotal()
val list = bankStatement.transactions.map {
    val currentTotal = total
    val totalBefore = currentTotal - it.amount
    total = totalBefore
    Something.fromThing(it, currentTotal, totalBefore)
}
d

dh44t

01/24/2018, 3:32 PM
that should work
Not sure why you need
val currentTotal
is still total
ok, I see it
z

ziggy42

01/24/2018, 3:33 PM
@menegatti suggested something better:
some.things.map { 
    Something.fromOtherThing(it, currentTotal, currentTotal - it.amount).also {
            currentTotal -= it.amount
    }
}
d

dh44t

01/24/2018, 3:33 PM
yeah
m

menegatti

01/24/2018, 3:34 PM
tbh, not sure it is better… I get a bit cautious around
also
because it might hinder readability
it is smaller, but I’d definitely say the way the total amount is being used is funky
z

ziggy42

01/24/2018, 3:36 PM
My version was very ugly imho. I like yours a lot more