[READ-ONLY] Mirror of https://github.com/probablykasper/csv-pipeline.
0

Configure Feed

Select the types of activity you want to include in your feed.

Add `count` transformer

Kasper (Jan 18, 2023, 6:34 AM +0100) a91e55d2 b9cb9e91

+29 -2
+1
CHANGELOG.md
··· 4 4 - Add Pipeline `select` method 5 5 - Add Pipeline `filter` & `filter_col` methods 6 6 - Add Pipeline `from_pipelines` constructor for merging pipelines together 7 + - Add `count` transformer 7 8 - Remember row order in transform_into 8 9 - Include source index in errors 9 10
+28 -2
src/transform.rs
··· 52 52 value: "".to_string(), 53 53 }) 54 54 } 55 - /// Sum the values in this column 55 + /// Sum the values in this column. 56 56 pub fn sum<'a, N>(self, init: N) -> Box<dyn Transform + 'a> 57 57 where 58 58 N: Display + AddAssign + FromStr + Clone + 'a, ··· 63 63 value: init, 64 64 }) 65 65 } 66 - /// Reduce the values from this column into a single value using a closure 66 + /// Reduce the values from this column into a single value using a closure. 67 67 pub fn reduce<'a, R, V>(self, reduce: R, init: V) -> Box<dyn Transform + 'a> 68 68 where 69 69 R: FnMut(V, &str) -> Result<V, Error> + 'a, ··· 74 74 from_col: self.from_col, 75 75 reduce, 76 76 value: init, 77 + }) 78 + } 79 + 80 + /// Count the rows that were reduced into this row. 81 + pub fn count(self) -> Box<dyn Transform> { 82 + Box::new(Count { 83 + name: self.name, 84 + value: 0, 77 85 }) 78 86 } 79 87 } ··· 182 190 self.name.clone() 183 191 } 184 192 } 193 + 194 + struct Count { 195 + name: String, 196 + value: u128, 197 + } 198 + impl Transform for Count { 199 + fn add_row(&mut self, _headers: &Headers, _row: &Row) -> Result<(), Error> { 200 + self.value += 1; 201 + Ok(()) 202 + } 203 + 204 + fn value(&self) -> String { 205 + self.value.to_string() 206 + } 207 + fn name(&self) -> String { 208 + self.name.clone() 209 + } 210 + }