<commit_before>use consumer::*;
use count::*;
use filter::*;
use flat_map::*;
use fold::*;
use group_by::*;
use inspect::*;
use map::*;
use max_by_key::*;
use max::*;
use min_by_key::*;
use min::*;
use skip_last::*;
use skip::*;
use subscription::*;
use sum::*;
use take_last::*;
use take::*;

pub trait Stream<T> {
    fn consume<C: Consumer<T>>(self, consumer: C);

    /// Count the number ofthe item received.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let vec = (0..10)
    ///     .to_stream()
    ///     .count()
    ///     .into_vec();
    /// assert!(vec == [10], "vec = {:?}", vec);
    /// ```
    fn count(self) -> Count<Self, T>
        where Self: Sized
    {
        Count::new(self)
    }

    /// Creates a stream which uses a closure to determine if an element should be emitted.
    /// The closure must return true or false. `filter()` creates a stream which calls this closure on each element. If the closure returns true, 
    /// then the element is returned. If the closure returns false, it will try again, and call the closure on the next element, seeing if it passes the test.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let mut vec = Vec::new();
    ///
    /// (0..5)
    ///     .to_stream()
    ///     .filter(|v| *v > 2)
    ///     .inspect(|v| vec.push(*v))
    ///     .subscribe();
    ///
    /// assert!(vec == &[3, 4], "vec = {:?}", vec);
    /// ``` 
    fn filter<F>(self, predicate: F) -> Filter<Self, F>
        where Self: Sized,
              F: FnMut(&mut T) -> bool
    {
        Filter::new(self, predicate)
    }

    /// Creates an stream that works like map, but flattens nested structure.
    /// The `map()` adapter is very useful, but only when the closure argument produces values. 
    /// If it produces a stream instead, there's an extra layer of indirection. flat_map() will remove this extra layer on its own.    /// If it produces a stream instead, there's an extra layer of indirection. flat_map() will remove this extra layer on its own.
    ///
    /// Another way of thinking about flat_map(): map()'s closure returns one item for each element, and flat_map()'s closure returns a stream for each element.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let vec = (0..4i32)
    ///     .to_stream()
    ///     .flat_map(|v| Value::new(v + 10))
    ///     .into_vec();
    ///
    /// assert!(vec == [10, 11, 12, 13], "vec = {:?}", vec);
    /// ```
    fn flat_map<F, SO, O>(self, func: F) -> Flatmap<Self, F, T, SO, O>
        where Self: Sized,
              F: FnMut(T) -> SO,
              SO: Stream<O>
    {
        Flatmap::new(self, func)
    }

    /// A stream adaptor that applies a function, producing a single, final value.
    ///`fold()` takes two arguments: an initial value, and a closure with two arguments: an 'accumulator', and an element. 
    /// It returns the value that the accumulator should have for the next iteration.
    ///
    /// The initial value is the value the accumulator will have on the first call.<commit_msg>fix documentation of flat_map<commit_after>use consumer::*;
use count::*;
use filter::*;
use flat_map::*;
use fold::*;
use group_by::*;
use inspect::*;
use map::*;
use max_by_key::*;
use max::*;
use min_by_key::*;
use min::*;
use skip_last::*;
use skip::*;
use subscription::*;
use sum::*;
use take_last::*;
use take::*;

pub trait Stream<T> {
    fn consume<C: Consumer<T>>(self, consumer: C);

    /// Count the number ofthe item received.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let vec = (0..10)
    ///     .to_stream()
    ///     .count()
    ///     .into_vec();
    /// assert!(vec == [10], "vec = {:?}", vec);
    /// ```
    fn count(self) -> Count<Self, T>
        where Self: Sized
    {
        Count::new(self)
    }

    /// Creates a stream which uses a closure to determine if an element should be emitted.
    /// The closure must return true or false. `filter()` creates a stream which calls this closure on each element. If the closure returns true, 
    /// then the element is returned. If the closure returns false, it will try again, and call the closure on the next element, seeing if it passes the test.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let mut vec = Vec::new();
    ///
    /// (0..5)
    ///     .to_stream()
    ///     .filter(|v| *v > 2)
    ///     .inspect(|v| vec.push(*v))
    ///     .subscribe();
    ///
    /// assert!(vec == &[3, 4], "vec = {:?}", vec);
    /// ``` 
    fn filter<F>(self, predicate: F) -> Filter<Self, F>
        where Self: Sized,
              F: FnMut(&mut T) -> bool
    {
        Filter::new(self, predicate)
    }

    /// Creates an stream that works like map, but flattens nested structure.
    /// The `map()` adapter is very useful, but only when the closure argument produces values. 
    /// If it produces a stream instead, there's an extra layer of indirection. flat_map() will remove this extra layer on its own.
    ///
    /// Another way of thinking about flat_map(): map()'s closure returns one item for each element, and flat_map()'s closure returns a stream for each element.
    ///
    /// # Examples
    ///
    /// ```
    /// use asyncplify::*;
    ///
    /// let vec = (0..4i32)
    ///     .to_stream()
    ///     .flat_map(|v| Value::new(v + 10))
    ///     .into_vec();
    ///
    /// assert!(vec == [10, 11, 12, 13], "vec = {:?}", vec);
    /// ```
    fn flat_map<F, SO, O>(self, func: F) -> Flatmap<Self, F, T, SO, O>
        where Self: Sized,
              F: FnMut(T) -> SO,
              SO: Stream<O>
    {
        Flatmap::new(self, func)
    }

    /// A stream adaptor that applies a function, producing a single, final value.
    ///`fold()` takes two arguments: an initial value, and a closure with two arguments: an 'accumulator', and an element. 
    /// It returns the value that the accumulator should have for the next iteration.
    ///
    /// The initial value is the value the accumulator will have on the first call.
{'fraction_non_alphanumeric': 0.1761666397545616, 'fraction_numerical': 0.007750686258679154, 'mean_word_length': 1.9693192713326941, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4460427', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1893, 'n_words': 697}