term

we want to translate all sorts of different terms (not just "pasta").

this language emits some INFORMATION from biting off "pizza".

TRANSLATED:



to define any term, we can define how it gets its INFORMATION.

here's the "pasta" term DEFINITION.

const pastaTerm = {
  check: checkPasta,
  bite: bitePasta,
  tail: tailPasta,
  travel: travelPasta,
  error: errorPasta,
}

to make the "pizza" term, we can do the same thing again.

const pizzaTerm = {
  check: checkPizza,
  bite: bitePizza,
  tail: tailPizza,
  travel: travelPizza,
  error: errorPizza,
}

we can now translate any term we want.

function translate(text, term) {
  return {
    check: term.check(text),
    bite: term.bite(text),
    tail: term.tail(text),
    travel: term.travel(text),
    error: term.error(text),
  }
}

back to the dream