joinWithAnd method Null safety

String joinWithAnd(
  1. [String? formatter(
    1. T input
    )?]
)

Implementation

String joinWithAnd([String? formatter(T input)?]) {
  formatter ??= (item) => item.toString();
  if (this.length < 3) {
    return this.join(" and ");
  } else {
    return mapPos((item, pos) {
      String? formatted = formatter!(item);
      switch (pos) {
        case IterationPosition.first:
        case IterationPosition.only:
          return formatted;
        case IterationPosition.middle:
          return ", $formatted";
        case IterationPosition.last:
          return ", and $formatted";
        default:
          return ", $formatted";
      }
    }).join("");
  }
}