Parameterized Input-molecules


Molecules can be parameterized by applying the input placeholder ? as a value to an attribute. The molecule then expects input for that attribute at runtime.

By assigning parameterized “Input-molecules” to variables we can re-use those variables to query for similar data structures where only some data part varies:

// 1 input parameter
val person = m(

val john = person("John").get.head
val lisa = person("Lisa").get.head

Of course more complex molecules would benefit even more from this approach.

Datomic cache and optimization

Datomic will cache and optimize the queries from such Input-molecules. This gives us an additional reason to use them.

Parameterized expressions

val personName  = m(
val johnOrLisas = personName("John" or "Lisa").get // OR

Multiple parameters

Molecules can have up to 3 ? placeholder parameters. Since we can apply expressions and logic to them it seems likely that this will satisfy the majority of all parameterized queires.

val person      = m(
val john        = person("John" and 42).get.head // AND
val johnOrJonas = person(("John" and 42) or ("Jonas" and 38)).get // AND/OR

Mix parameterized and static expressions

val americansYoungerThan = m(<(?)"USA"))
val americanKids         = americansYoungerThan(13).get
val americanBabies       = americansYoungerThan(1).get

For more examples, please see the Seattle examples