Skip to content

Instantly share code, notes, and snippets.

@faizul14
Created August 12, 2023 12:30
Show Gist options
  • Save faizul14/80f9b0b286d8387b912e5261fb36b9ec to your computer and use it in GitHub Desktop.
Save faizul14/80f9b0b286d8387b912e5261fb36b9ec to your computer and use it in GitHub Desktop.
val numbers = mutableListOf(1, 2, 3)
val doubled = numbers.also {
it.add(4)
it.mapInPlace { num -> num * 2 }
}
println("Original List: $numbers")
println("Doubled List: $doubled")
// Output:
// Original List: [1, 2, 3, 4]
// Doubled List: [2, 4, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment