From ab9254111993b52d75119ede695a86ef014e8916 Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Sun, 4 Dec 2022 08:15:37 +0000 Subject: [PATCH] Use tuple_map to map tuples --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/day04/mod.rs | 11 +++-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5540719..7231a52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,6 +27,7 @@ dependencies = [ "chrono", "itertools", "regex", + "tuple-map", ] [[package]] @@ -303,6 +304,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "tuple-map" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d5919d7121237af683b7fa982450597b1eaa2643e597aec3b519e4e5ab3d62" + [[package]] name = "unicode-ident" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index 965ed56..ffbb899 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" chrono = "0.4.23" itertools = "0.10.5" regex = "1.7.0" +tuple-map = "0.4.0" [features] default = ["part1", "part2", "today"] diff --git a/src/day04/mod.rs b/src/day04/mod.rs index a6f9555..3ceb09a 100644 --- a/src/day04/mod.rs +++ b/src/day04/mod.rs @@ -1,10 +1,8 @@ use crate::read; +use tuple_map::*; fn get_ranges(elf: &str) -> std::ops::RangeInclusive { - let r = elf - .split_once('-') - .map(|e| (e.0.parse().unwrap(), e.1.parse().unwrap())) - .unwrap(); + let r = elf.split_once('-').unwrap().map(|e| e.parse().unwrap()); r.0..=r.1 } @@ -13,10 +11,7 @@ pub fn run() { let lines = input .lines() - .map(|l| { - let pairs = l.split_once(',').unwrap(); - (get_ranges(pairs.0), get_ranges(pairs.1)) - }) + .map(|l| l.split_once(',').unwrap().map(get_ranges)) .collect::>(); #[cfg(feature = "part1")] {