2/5

a!update(): book seats without double-booking

Medium

A booking page keeps a row's seats as a list of "free" and "taken". When a customer books some seats, mark them all "taken" and return the row.

Watch out

  • If any seat in the booking is already taken, the whole booking fails and the row comes back unchanged: half a booking is worse than none.
  • One a!update() call can set several positions to the same value.

Inputs

  • ri!seats — List of Text
  • ri!booking — List of Integer

ri! Rule Inputs

ri!seatsList of Text
{
  "free",
  "free",
  "taken",
  "free"
}
ri!bookingList of Integer
{
  1,
  4
}

Example 1 — Two free seats

Input: ri!seats
{
  "free",
  "free",
  "taken",
  "free"
}
Input: ri!booking
{
  1,
  4
}
Output:
{
  "taken",
  "free",
  "taken",
  "taken"
}

Example 2 — One seat already taken

Input: ri!seats
{
  "free",
  "free",
  "taken",
  "free"
}
Input: ri!booking
{
  2,
  3
}
Output:
{
  "free",
  "free",
  "taken",
  "free"
}

Example 3 — A single seat

Input: ri!seats
{
  "free",
  "free",
  "taken",
  "free"
}
Input: ri!booking
{2}
Output:
{
  "free",
  "taken",
  "taken",
  "free"
}

Example 4 — Nothing booked

Input: ri!seats
{
  "free",
  "free",
  "taken",
  "free"
}
Input: ri!booking
{}
Output:
{
  "free",
  "free",
  "taken",
  "free"
}

Appian Expression Tips

  • • Use ri!variableName for rule inputs
  • • Use a!localVariables(local!x: …, body) for locals
  • • Use a!forEach(items: …, expression: fv!item) to iterate
  • • Use where() / reject(fn!isnull, list) to filter