Created
October 2, 2022 13:15
-
-
Save hector6872/558e64d672462fe7f753f8e86a1cbccc to your computer and use it in GitHub Desktop.
Map It Please for Kotlin
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
/** | |
* Map it please. Returns a list containing the results of applying the | |
* given transform function to each element in the original collection. | |
* | |
* OP: https://twitter.com/jeranfox/status/1575133458631999488 | |
*/ | |
inline fun <TYPE, RESULT> Iterable<TYPE>.mip(transform: TYPE.() -> RESULT): List<RESULT> = map { it.transform() } | |
/** before: | |
* users.map { it.firstName } | |
* | |
* after: | |
* users.map { firstName } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment