selectFrom<LogicType extends Logic> method

LogicType selectFrom<LogicType extends Logic>(
  1. List<LogicType> busList, {
  2. dynamic defaultValue,
  3. LogicType outputGenerator({
    1. String? name,
    })?,
  4. String name = 'selectFrom',
})

Performs a Logic index based selection on 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 LogicType within the logicList using the index of Logic type.

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

Example:

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

Implementation

LogicType selectFrom<LogicType extends Logic>(
  List<LogicType> busList, {
  dynamic defaultValue,
  LogicType Function({String? name})? outputGenerator,
  String name = 'selectFrom',
}) {
  if (busList.isEmpty) {
    throw LogicConstructionException(
      'selectFrom requires at least one value.',
    );
  }
  return cases<LogicType>(
    this,
    {
      for (var index = 0; index < busList.length; index++)
        index: busList[index],
    },
    conditionalType: ConditionalType.unique,
    defaultValue: defaultValue ?? 0,
    outputGenerator: outputGenerator,
    name: name,
  );
}