summaryrefslogtreecommitdiffstats
path: root/src/parse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.rs')
-rw-r--r--src/parse.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/parse.rs b/src/parse.rs
index 903ad2f..3674a25 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -63,3 +63,21 @@ pub fn digit_grid(lines: impl Iterator<Item = String>) -> Grid<u8> {
})
.collect()
}
+
+// false positive, doing its suggestion gives borrow checker errors
+#[allow(clippy::redundant_closure)]
+pub fn grid<F, T>(lines: impl Iterator<Item = String>, f: F) -> Grid<T>
+where
+ F: Fn(u8) -> T,
+ T: Clone + Default + Eq + PartialEq,
+{
+ lines
+ .map(|s| {
+ s.as_bytes()
+ .iter()
+ .copied()
+ .map(|b| f(b))
+ .collect::<Vec<_>>()
+ })
+ .collect()
+}