//! Provider of [`IsItemOfExt`].

use crate::prelude::*;

/// Extention trait for method [`is_item_of`](Self::is_item_of).
pub trait IsItemOfExt<T> {
    /// Returns `true` if this item is contained in iterator.
    ///
    /// # Examples
    ///
    /// ```
    /// use subject::prelude::*;
    /// use subject::exts::IsItemOfExt;
    ///
    /// let arr = [1, 3, 4, 7];
    /// assert!(S(&3).is_item_of(arr.iter()));
    /// assert!(!S(&5).is_item_of(arr.iter()));
    /// ```
    fn is_item_of<I>(&self, iter: I) -> bool
    where
        Self: Sized,
        T: PartialEq,
        I: IntoIterator<Item = T>;
}

impl<T> IsItemOfExt<T> for S<T> {
    fn is_item_of<I>(&self, iter: I) -> bool
    where
        Self: Sized,
        T: PartialEq,
        I: IntoIterator<Item = T>,
    {
        iter.into_iter().any(|x| x.eq(&self.0))
    }
}
