Created
February 26, 2020 14:56
-
-
Save michael-simons/0e25ac4d9b7e8897cc16e8f04b140d95 to your computer and use it in GitHub Desktop.
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
inline fun String.asParameter() = "\$" + this | |
infix fun String.Companion.asParameter(s: String) = "\$" + s |
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
class ParameterTest { | |
@Test | |
fun `named parameters in multiline strings shouldn't be that hard`() { | |
""" | |
MATCH (n:Something {n.name: ${"someParameter".asParameter()}} | |
WHERE n.someProperty = ${String asParameter "someother"} | |
""".trimIndent().apply { | |
assertEquals("MATCH (n:Something {n.name: \$someParameter}\nWHERE n.someProperty = \$someother", this) | |
}; | |
} | |
} |
Michael H. suggested p
as well ;)
I'd say that's fine for a global method, but it's not something I'd attach to String
…
I'm unsure how the Kotlin community thinks about it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would go with:
Or maybe
p
orP
instead ofparam