1use std::str::FromStr;
2
3pub fn to_lines(input: &str) -> Vec<String> {
4 input.lines().map(String::from).collect()
5}
6
7pub fn parse_strings<T>(input: &[String]) -> Result<Vec<T>, T::Err>
8where
9 T: FromStr,
10{
11 input.iter().map(|s| s.parse()).collect()
12}
13
14pub fn transpose<T>(input: &Vec<Vec<T>>) -> Vec<Vec<T>>
15where
16 T: Copy,
17{
18 assert!(input.windows(2).all(|w| w[0].len() == w[1].len()));
19 (0..input[0].len())
20 .map(|i| input.iter().map(|line| line[i]).collect())
21 .collect()
22}