Skip to content

Instantly share code, notes, and snippets.

@michael-simons
Created February 26, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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)
};
}
}
@corneil
Copy link

corneil commented Feb 26, 2020

I would go with:

fun param(p: String) : "\$" + p
"""
MATCH (n: Node {n.name: ${param("someParameter")}})
"""

Or maybe p or P instead of param

@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