Parameterized Input-molecules

Tests: 1 input, 2 inputs, 3 inputs

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 caches and optimizes queries from input molecules so performance-wise it’s a good idea 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.

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 and tests for 1 input, 2 inputs, 3 inputs

(All getters have an asynchronous equivalent. Synchronous getters shown for brevity)