Skip to content

Instantly share code, notes, and snippets.

@hrules6872
Created October 2, 2022 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrules6872/558e64d672462fe7f753f8e86a1cbccc to your computer and use it in GitHub Desktop.
Save hrules6872/558e64d672462fe7f753f8e86a1cbccc to your computer and use it in GitHub Desktop.
Map It Please for Kotlin
/**
* 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