/rust/registry/src/index.crates.io-1949cf8c6b5b557f/itertools-0.14.0/src/concat_impl.rs
Line | Count | Source |
1 | | /// Combine all an iterator's elements into one element by using [`Extend`]. |
2 | | /// |
3 | | /// [`IntoIterator`]-enabled version of [`Itertools::concat`](crate::Itertools::concat). |
4 | | /// |
5 | | /// This combinator will extend the first item with each of the rest of the |
6 | | /// items of the iterator. If the iterator is empty, the default value of |
7 | | /// `I::Item` is returned. |
8 | | /// |
9 | | /// ```rust |
10 | | /// use itertools::concat; |
11 | | /// |
12 | | /// let input = vec![vec![1], vec![2, 3], vec![4, 5, 6]]; |
13 | | /// assert_eq!(concat(input), vec![1, 2, 3, 4, 5, 6]); |
14 | | /// ``` |
15 | 0 | pub fn concat<I>(iterable: I) -> I::Item |
16 | 0 | where |
17 | 0 | I: IntoIterator, |
18 | 0 | I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default, |
19 | | { |
20 | 0 | iterable |
21 | 0 | .into_iter() |
22 | 0 | .reduce(|mut a, b| { |
23 | 0 | a.extend(b); |
24 | 0 | a |
25 | 0 | }) |
26 | 0 | .unwrap_or_default() |
27 | 0 | } |