withRowsWhereTemplate method

DataFrame withRowsWhereTemplate({
  1. required String template,
  2. required bool predicate(
    1. String
    ),
  3. String startQuote = '{',
  4. String endQuote = '}',
})

A new data frame with the rows that meet a predicate based on a template.

Example:

final d = """
  a,b,c
 fu,5,n
  f,3,ull
  f,9,un
 pu,3,n
""".parseAsCsv();

print(d.withRowsWhereTemplate(
  template: "{a}{c}",
  predicate: (result) => result == "fun",
));

.-.----.----.
|b|a   |c   |
:-+----+----:
|5|fu  |n   |
|9|f   |un  |
'-'----'----'

Implementation

DataFrame withRowsWhereTemplate({
  required String template,
  required bool Function(String) predicate,
  String startQuote = '{',
  String endQuote = '}',
}) {
  final values = _templateResults(
    template,
    startQuote: startQuote,
    endQuote: endQuote,
  );
  return withRowsAtIndices([
    for (var i = 0; i < rowNumber; i++)
      if (predicate(values[i])) i
  ]);
}