parseFromInlineList<T> function

List<T>? parseFromInlineList<T>(
  1. String? s,
  2. Pattern delimiter, [
  3. StringMapper<T>? mapper,
  4. List<T>? def,
])

Parses s as a inline list.

delimiter Elements delimiter. mapper Maps elements to another type.

Implementation

List<T>? parseFromInlineList<T>(String? s, Pattern delimiter,
    [StringMapper<T>? mapper, List<T>? def]) {
  if (s == null) return def;
  s = s.trim();
  if (s.isEmpty) return def;

  mapper ??= (s) => s as T;

  var parts = s.split(delimiter);

  var list = <T>[];

  for (var n in parts) {
    list.add(mapper(n));
  }

  return list;
}