withNumericColumnFromTemplate method
A new data frame with a numeric column generated from a template.
Example:
print(petals.withHead(5));
print(petals.withHead(5).withNumericColumnFromTemplate(
name: "letters",
template: "{species}",
generator: (result) => result.length,
));
.--.------------.-----------.------------.
|id|petal_length|petal_width|species |
:--+------------+-----------+------------:
|1 |1.4 |0.2 |setosa |
|2 |1.4 |0.2 |setosa |
|3 |1.3 |0.2 |setosa |
|4 |1.5 |0.2 |setosa |
|51|4.7 |1.4 |versicolor |
'--'------------'-----------'------------'
.--.------------.-----------.-------.------------.
|id|petal_length|petal_width|letters|species |
:--+------------+-----------+-------+------------:
|1 |1.4 |0.2 |6 |setosa |
|2 |1.4 |0.2 |6 |setosa |
|3 |1.3 |0.2 |6 |setosa |
|4 |1.5 |0.2 |6 |setosa |
|51|4.7 |1.4 |10 |versicolor |
'--'------------'-----------'-------'------------'
Implementation
DataFrame withNumericColumnFromTemplate({
required String name,
required String template,
required num Function(String) generator,
String startQuote = '{',
String endQuote = '}',
}) {
if (!_columnNameOkay(name)) {
throw PackhorseError.badColumnName(name);
}
return copy
..numericColumns[name] = NumericColumn(
_templateResults(
template,
startQuote: startQuote,
endQuote: endQuote,
).map(generator),
);
}