Skip to content

Instantly share code, notes, and snippets.

@michael-simons
Created February 26, 2020 14:56
Show Gist options
  • Save michael-simons/0e25ac4d9b7e8897cc16e8f04b140d95 to your computer and use it in GitHub Desktop.
Save michael-simons/0e25ac4d9b7e8897cc16e8f04b140d95 to your computer and use it in GitHub Desktop.
inline fun String.asParameter() = "\$" + this
infix fun String.Companion.asParameter(s: String) = "\$" + s
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-simons
Copy link
Author

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