1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
use Hash;
/// Returns the first item of `iter` that has already appeared earlier in it, or `None` when
/// every item is unique.
///
/// Unlike [`array::duplicates`](crate::array::duplicates), this stops at the first repeat, so it
/// works on an infinite or otherwise unbounded iterator instead of requiring an already-collected
/// slice.
///
/// # Arguments
///
/// - `iter` - The items to scan, in order.
///
/// # Returns
///
/// The first repeated item, or `None` when there is none.
///
/// # Examples
///
/// ```
/// use helpers4::iter::first_duplicate;
///
/// assert_eq!(first_duplicate([1, 2, 3, 2, 1]), Some(2));
/// assert_eq!(first_duplicate(["a", "b", "c"]), None);
/// ```