| 1 | use crate::Itertools; | 
| 2 |  | 
|---|
| 3 | /// Combine all an iterator's elements into one element by using [`Extend`]. | 
|---|
| 4 | /// | 
|---|
| 5 | /// [`IntoIterator`]-enabled version of [`Itertools::concat`]. | 
|---|
| 6 | /// | 
|---|
| 7 | /// This combinator will extend the first item with each of the rest of the | 
|---|
| 8 | /// items of the iterator. If the iterator is empty, the default value of | 
|---|
| 9 | /// `I::Item` is returned. | 
|---|
| 10 | /// | 
|---|
| 11 | /// ```rust | 
|---|
| 12 | /// use itertools::concat; | 
|---|
| 13 | /// | 
|---|
| 14 | /// let input = vec![vec![1], vec![2, 3], vec![4, 5, 6]]; | 
|---|
| 15 | /// assert_eq!(concat(input), vec![1, 2, 3, 4, 5, 6]); | 
|---|
| 16 | /// ``` | 
|---|
| 17 | pub fn concat<I>(iterable: I) -> I::Item | 
|---|
| 18 | where | 
|---|
| 19 | I: IntoIterator, | 
|---|
| 20 | I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default, | 
|---|
| 21 | { | 
|---|
| 22 | #[ allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce` | 
|---|
| 23 | iterableOption<{unknown}> | 
|---|
| 24 | .into_iter() | 
|---|
| 25 | .fold1(|mut a, b| { | 
|---|
| 26 | a.extend(b); | 
|---|
| 27 | a | 
|---|
| 28 | }) | 
|---|
| 29 | .unwrap_or_default() | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|