Skip to content

Instantly share code, notes, and snippets.

@mcalavera81
Created September 21, 2022 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcalavera81/7895f565c0a69ce1ee44a112ae945bfe to your computer and use it in GitHub Desktop.
Save mcalavera81/7895f565c0a69ce1ee44a112ae945bfe to your computer and use it in GitHub Desktop.
val raw: List<Char> = "aabcccccaaa".map { it }
println(raw.toList().fold(listOf<Char>()) { acc, value ->
if (acc.isEmpty()) listOf(value)
else {//a2, b
if (acc.last() == value) acc
else acc + value
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment