Last active
April 19, 2024 18:01
-
-
Save ayer-ribeiro/de19d6d0b9899c3b375e090031b4ff28 to your computer and use it in GitHub Desktop.
Kotlin String Wrapper Util
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
package dev.ayer.string.wrapper | |
interface Wrapper { | |
val begin: String | |
val end: String | |
} | |
object Parentheses : Wrapper { | |
override val begin: String = "(" | |
override val end: String = ")" | |
} | |
object Brackets : Wrapper { | |
override val begin: String = "[" | |
override val end: String = "]" | |
} | |
object Braces : Wrapper { | |
override val begin: String = "{" | |
override val end: String = "}" | |
} | |
fun CharSequence.wrapped(with: Wrapper): String { | |
return "${with.begin}$this${with.end}" | |
} | |
// Usage example: | |
// it.paramName.wrapped(with = Parentheses) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment