Created
November 3, 2017 16:12
-
-
Save rekendahl/b299d5b86e0a7cb6844dddecd3408fe9 to your computer and use it in GitHub Desktop.
Kotlin list merge example
This file contains 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
if (defines[macroName]?.body?.isNotEmpty() == true) { | |
val mergedList = mutableListOf<Pair<IElementType?, String?>>() | |
for (tokenInfo in defines[macroName]?.body.orEmpty()) { | |
val tokenType = tokenInfo.first | |
val tokenName = tokenInfo.second | |
when (tokenType) { | |
CD_TICK_TICK -> { | |
val lastToken = mergedList.last() | |
mergedList.remove(lastToken) | |
val nextToken = defines[macroName]?.body?.iterator()?.next() | |
val mergedString = lastToken.second + (nextToken?.second ?: "") | |
val mergedPair = Pair<IElementType?, String?>(lastToken.first, mergedString) | |
mergedList.add(mergedPair) | |
} | |
else -> { | |
mergedList.add(tokenInfo) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment