ivanakcheurov / desh.net

Parser, engine and tools for desh language in .net
MIT License
2 stars 0 forks source link

Query all variations #3

Open ivanakcheurov opened 5 years ago

ivanakcheurov commented 5 years ago

Request

Given a Desh document, retrieve all possible variations that an input object is allowed to have.

Example

Let's take an example of an electronics shop where you can order a phone, tablet or laptop. There are business rules which devices can be ordered. A Desh that encodes what can be ordered:

product_type:
  - [phone, tablet]:
      cpu_count:
        - 1:
            ram_GB: [1, 2, 3, 4]
        - [2, 4]:
            ram_GB: [2, 3, 4, 6, 8]
  - [laptop]:
      cpu_count:
        - 4:
            ram_GB: [16, 24, 32]
            storage_type:
              - SSD:
                  storage_capacity_GB: [256, 384, 512, 1024]
              - HDD:
                  storage_capacity_TB: [1, 2, 3, 4]

In this case an order (input object) could look like this:

product_type: tablet
cpu_count: 4
ram_GB: 6

One may want to know all the possible device configurations that the shop can sell without brute-force. In other words, all variations of an order. For this case all variations would be a union of the following variations:

product_type(phone, tablet) X cpu_count (1) X RAM (1, 2, 3, 4)
product_type (phone, tablet) X cpu_count (2, 4) X RAM (2, 3, 4, 6, 8)
product_type(laptop) X cpu_count (4) X RAM (16, 24, 32) X SSD_GB (256, 384, 512, 1024)
product_type (laptop) X cpu_count (4) X RAM (16, 24, 32) X HDD_TB (1, 2, 3, 4)