selectFrom method

Logic selectFrom(
  1. List<Logic> busList, {
  2. Logic? defaultValue,

Performs a Logic index based selection on an List of Logic named busList.

Using the Logic index on which selectFrom is performed on and a List of Logic named busList for index based selection, we can select any valid element of type Logic within the logicList using the index of Logic type.

Alternatively we can approach this with busList.selectIndex(index)


// ordering matches closer to array indexing with `0` index-based.
selected <= index.selectFrom(busList);


Logic selectFrom(List<Logic> busList, {Logic? defaultValue}) {
  final selected = Logic(
      name: 'selectFrom',
      width: busList.first.width,
      naming: Naming.mergeable);

            for (var i = 0; i < busList.length; i++)
              CaseItem(Const(i, width: width), [selected < busList[i]])
          conditionalType: ConditionalType.unique,
          defaultItem: [selected < (defaultValue ?? 0)])

  return selected;