Skip to content

Commit

Permalink
Improved docstrings for free::chain
Browse files Browse the repository at this point in the history
- Improved the description of the function and added example.
- Fixed errors in PR
- Implemented suggestions by phimuemue
  • Loading branch information
JoelMon committed Aug 25, 2022
1 parent 7a27408 commit 94326f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/free.rs
Expand Up @@ -128,17 +128,23 @@ pub fn zip<I, J>(i: I, j: J) -> Zip<I::IntoIter, J::IntoIter>
i.into_iter().zip(j)
}

/// Create an iterator that first iterates `i` and then `j`.

/// Takes two iterators and creates a new iterator over both in sequence.
///
/// [`IntoIterator`] enabled version of [`Iterator::chain`].
///
/// ## Example
/// ```
/// use itertools::chain;
///
/// let mut result:Vec<i32> = Vec::new();
///
/// for elt in chain(&[1, 2, 3], &[4]) {
/// /* loop body */
/// for element in chain(&[1, 2, 3] , &[4]) {
/// result.push(*element);
/// }
/// assert_eq!(result, vec![1, 2, 3, 4]);
/// ```
#[deprecated(note="Use std::iter::Chain instead", since="1.0.0")]
pub fn chain<I, J>(i: I, j: J) -> iter::Chain<<I as IntoIterator>::IntoIter, <J as IntoIterator>::IntoIter>
where I: IntoIterator,
J: IntoIterator<Item = I::Item>
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -2271,15 +2271,15 @@ pub trait Itertools : Iterator {
/// ```
///
/// Which, for non-associative functions, will typically produce a different
/// result than the linear call tree used by `fold1`:
/// result than the linear call tree used by [`Iterator::reduce`]:
///
/// ```text
/// 1 2 3 4 5 6 7
/// │ │ │ │ │ │ │
/// └─f─f─f─f─f─f
/// ```
///
/// If `f` is associative, prefer the normal `fold1` instead.
/// If `f` is associative, prefer the normal [`Iterator::reduce`] instead.
///
/// ```
/// use itertools::Itertools;
Expand Down

0 comments on commit 94326f3

Please sign in to comment.