summaryrefslogtreecommitdiffstats
path: root/src/parse.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-25 00:29:43 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-25 00:29:43 -0500
commit3dfa5bd6227ce8654f75371bd7de06b0cbe92f87 (patch)
treea81539784e9c1d8e93e9b93ff3fcd32aa9d80ae1 /src/parse.rs
parentefd2635dd73b7806d75d23e21f37bd82288820c1 (diff)
downloadadvent-of-code-3dfa5bd6227ce8654f75371bd7de06b0cbe92f87.tar.gz
advent-of-code-3dfa5bd6227ce8654f75371bd7de06b0cbe92f87.zip
day 25
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()
+}