Created
July 27, 2018 06:37
-
-
Save jeremylcarter/1d0d5df3224ff6b739dd73a3067d2cc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T, R> Iterable<T>.mapWithPrevious(transform: (previous: R?, it: T) -> R): List<R> { | |
var previous: R? = null | |
return this.map { it -> | |
val transformed = transform(previous, it) | |
previous = transformed | |
transformed | |
} | |
} | |
val mapped = someCollection.mapWithPrevious { previousTransformation, it -> | |
if (previousTransformation !=null) { | |
// Use data from the previous transformation? | |
SomeClass(12345,previousTransformation.balance) | |
} else { | |
SomeClass(12345, 0.00) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment