Skip to content

Commit b9d270f

Browse files
committed
fix some typos and add some examples that panic
1 parent 2319e23 commit b9d270f

File tree

8 files changed

+50
-19
lines changed

8 files changed

+50
-19
lines changed

src/adaptors/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ where
522522
debug_fmt_fields!(TakeWhileRef, iter);
523523
}
524524

525-
/// Create a new `TakeWhileRef` from a reference to clonable iterator.
525+
/// Create a new `TakeWhileRef` from a reference to cloneable iterator.
526526
pub fn take_while_ref<I, F>(iter: &mut I, f: F) -> TakeWhileRef<'_, I, F>
527527
where
528528
I: Iterator + Clone,
@@ -626,7 +626,7 @@ pub trait HasCombination<I>: Sized {
626626
type Combination: From<I> + Iterator<Item = Self>;
627627
}
628628

629-
/// Create a new `TupleCombinations` from a clonable iterator.
629+
/// Create a new `TupleCombinations` from a cloneable iterator.
630630
pub fn tuple_combinations<T, I>(iter: I) -> TupleCombinations<I, T>
631631
where
632632
I: Iterator,

src/combinations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub type Combinations<I> = CombinationsGeneric<I, Vec<usize>>;
1414
/// Iterator for const generic combinations returned by [`.array_combinations()`](crate::Itertools::array_combinations)
1515
pub type ArrayCombinations<I, const K: usize> = CombinationsGeneric<I, [usize; K]>;
1616

17-
/// Create a new `Combinations` from a clonable iterator.
17+
/// Create a new `Combinations` from a cloneable iterator.
1818
pub fn combinations<I: Iterator>(iter: I, k: usize) -> Combinations<I>
1919
where
2020
I::Item: Clone,
2121
{
2222
Combinations::new(iter, (0..k).collect())
2323
}
2424

25-
/// Create a new `ArrayCombinations` from a clonable iterator.
25+
/// Create a new `ArrayCombinations` from a cloneable iterator.
2626
pub fn array_combinations<I: Iterator, const K: usize>(iter: I) -> ArrayCombinations<I, K>
2727
where
2828
I::Item: Clone,

src/combinations_with_replacement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
debug_fmt_fields!(CombinationsWithReplacementGeneric, indices, pool, first);
3737
}
3838

39-
/// Create a new `ArrayCombinationsWithReplacement`` from a clonable iterator.
39+
/// Create a new `ArrayCombinationsWithReplacement`` from a cloneable iterator.
4040
pub fn array_combinations_with_replacement<I: Iterator, const K: usize>(
4141
iter: I,
4242
) -> ArrayCombinationsWithReplacement<I, K>
@@ -45,7 +45,7 @@ where
4545
{
4646
ArrayCombinationsWithReplacement::new(iter, [0; K])
4747
}
48-
/// Create a new `CombinationsWithReplacement` from a clonable iterator.
48+
/// Create a new `CombinationsWithReplacement` from a cloneable iterator.
4949
pub fn combinations_with_replacement<I>(iter: I, k: usize) -> CombinationsWithReplacement<I>
5050
where
5151
I: Iterator,

src/either_or_both.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<T> EitherOrBoth<T, T> {
467467
/// Return either value of left, right, or apply a function `f` to both values if both are present.
468468
/// The input function has to return the same type as both Right and Left carry.
469469
///
470-
/// This function can be used to preferrably extract the left resp. right value,
470+
/// This function can be used to preferably extract the left resp. right value,
471471
/// but fall back to the other (i.e. right resp. left) if the preferred one is not present.
472472
///
473473
/// # Examples

src/grouping_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646

4747
/// `GroupingMapBy` is an intermediate struct for efficient group-and-fold operations.
4848
///
49-
/// See [`GroupingMap`] for more informations.
49+
/// See [`GroupingMap`] for more information.
5050
pub type GroupingMapBy<I, F> = GroupingMap<MapForGrouping<I, F>>;
5151

5252
/// `GroupingMap` is an intermediate struct for efficient group-and-fold operations.

src/kmerge_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
}
9898
}
9999

100-
/// An iterator adaptor that merges an abitrary number of base iterators in ascending order.
100+
/// An iterator adaptor that merges an arbitrary number of base iterators in ascending order.
101101
/// If all base iterators are sorted (ascending), the result is sorted.
102102
///
103103
/// Iterator element type is `I::Item`.
@@ -146,7 +146,7 @@ where
146146
kmerge_by(iterable, KMergeByLt)
147147
}
148148

149-
/// An iterator adaptor that merges an abitrary number of base iterators
149+
/// An iterator adaptor that merges an arbitrary number of base iterators
150150
/// according to an ordering function.
151151
///
152152
/// Iterator element type is `I::Item`.

src/lib.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,28 @@ pub trait Itertools: Iterator {
622622
///
623623
/// **Panics** if the iterators reach an end and they are not of equal
624624
/// lengths.
625+
///
626+
/// # Examples
627+
///
628+
/// ```
629+
/// use itertools::Itertools;
630+
///
631+
/// let a = [1, 2];
632+
/// let b = [3, 4];
633+
///
634+
/// let zipped: Vec<_> = a.into_iter().zip_eq(b.into_iter()).collect();
635+
///
636+
/// assert_eq!(zipped, vec![(1, 3), (2, 4)]);
637+
/// ```
638+
///
639+
/// ```should_panic
640+
/// use itertools::Itertools;
641+
///
642+
/// let a = [1, 2];
643+
/// let b = [3, 4, 5];
644+
/// // This example panics because the iterators are not of equal length.
645+
/// let _zipped: Vec<_> = a.iter().zip_eq(b.iter()).collect();
646+
/// ```
625647
#[inline]
626648
fn zip_eq<J>(self, other: J) -> ZipEq<Self, J::IntoIter>
627649
where
@@ -731,6 +753,8 @@ pub trait Itertools: Iterator {
731753
///
732754
/// **Panics** if `size` is 0.
733755
///
756+
/// # Examples
757+
///
734758
/// ```
735759
/// use itertools::Itertools;
736760
///
@@ -744,6 +768,13 @@ pub trait Itertools: Iterator {
744768
/// assert_eq!(4, chunk.sum());
745769
/// }
746770
/// ```
771+
///
772+
/// ```should_panic
773+
/// use itertools::Itertools;
774+
/// let data = vec![1, 2, 3];
775+
/// // Panics because chunk size is 0.
776+
/// let _chunks = data.into_iter().chunks(0);
777+
/// ```
747778
#[cfg(feature = "use_alloc")]
748779
fn chunks(self, size: usize) -> IntoChunks<Self>
749780
where
@@ -872,7 +903,7 @@ pub trait Itertools: Iterator {
872903
/// Split into an iterator pair that both yield all elements from
873904
/// the original iterator.
874905
///
875-
/// **Note:** If the iterator is clonable, prefer using that instead
906+
/// **Note:** If the iterator is cloneable, prefer using that instead
876907
/// of using this method. Cloning is likely to be more efficient.
877908
///
878909
/// Iterator element type is `Self::Item`.
@@ -1003,7 +1034,7 @@ pub trait Itertools: Iterator {
10031034
/// as long as the original iterator produces `Ok` values.
10041035
///
10051036
/// If the original iterable produces an error at any point, the adapted
1006-
/// iterator ends and it will return the error iself.
1037+
/// iterator ends and it will return the error itself.
10071038
///
10081039
/// Otherwise, the return value from the closure is returned wrapped
10091040
/// inside `Ok`.
@@ -1601,11 +1632,11 @@ pub trait Itertools: Iterator {
16011632
/// #[derive(Debug, PartialEq)]
16021633
/// struct NoCloneImpl(i32);
16031634
///
1604-
/// let non_clonable_items: Vec<_> = vec![1, 2, 3, 4, 5]
1635+
/// let non_cloneable_items: Vec<_> = vec![1, 2, 3, 4, 5]
16051636
/// .into_iter()
16061637
/// .map(NoCloneImpl)
16071638
/// .collect();
1608-
/// let filtered: Vec<_> = non_clonable_items
1639+
/// let filtered: Vec<_> = non_cloneable_items
16091640
/// .into_iter()
16101641
/// .take_while_inclusive(|n| n.0 % 3 != 0)
16111642
/// .collect();
@@ -3797,7 +3828,7 @@ pub trait Itertools: Iterator {
37973828
/// value of type `K` will be used as key to identify the groups and the
37983829
/// value of type `V` as value for the folding operation.
37993830
///
3800-
/// See [`GroupingMap`] for more informations
3831+
/// See [`GroupingMap`] for more information
38013832
/// on what operations are available.
38023833
#[cfg(feature = "use_std")]
38033834
fn into_grouping_map<K, V>(self) -> GroupingMap<Self>
@@ -3814,7 +3845,7 @@ pub trait Itertools: Iterator {
38143845
/// The values from this iterator will be used as values for the folding operation
38153846
/// while the keys will be obtained from the values by calling `key_mapper`.
38163847
///
3817-
/// See [`GroupingMap`] for more informations
3848+
/// See [`GroupingMap`] for more information
38183849
/// on what operations are available.
38193850
#[cfg(feature = "use_std")]
38203851
fn into_grouping_map_by<K, V, F>(self, key_mapper: F) -> GroupingMapBy<Self, F>
@@ -4334,7 +4365,7 @@ pub trait Itertools: Iterator {
43344365
}
43354366
}
43364367

4337-
/// Return the postions of the minimum and maximum elements of an
4368+
/// Return the positions of the minimum and maximum elements of an
43384369
/// iterator, as determined by the specified function.
43394370
///
43404371
/// The return value is a variant of [`MinMaxResult`] like for
@@ -4382,7 +4413,7 @@ pub trait Itertools: Iterator {
43824413
}
43834414
}
43844415

4385-
/// Return the postions of the minimum and maximum elements of an
4416+
/// Return the positions of the minimum and maximum elements of an
43864417
/// iterator, as determined by the specified comparison function.
43874418
///
43884419
/// The return value is a variant of [`MinMaxResult`] like for

src/powerset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
debug_fmt_fields!(Powerset, combs);
3232
}
3333

34-
/// Create a new `Powerset` from a clonable iterator.
34+
/// Create a new `Powerset` from a cloneable iterator.
3535
pub fn powerset<I>(src: I) -> Powerset<I>
3636
where
3737
I: Iterator,

0 commit comments

Comments
 (0)