Skip to content

Instantly share code, notes, and snippets.

@ayer-ribeiro
Last active April 19, 2024 18:01
Show Gist options
  • Save ayer-ribeiro/de19d6d0b9899c3b375e090031b4ff28 to your computer and use it in GitHub Desktop.
Save ayer-ribeiro/de19d6d0b9899c3b375e090031b4ff28 to your computer and use it in GitHub Desktop.
Kotlin String Wrapper Util
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