pub fn apply_with_time<F>(
        &self,
        other: &TimeSeries<'a, T>,
        func: F,
    ) -> Result<TimeSeries<'a, T>, TimeSeriesError>
    where
        F: FnMut((DateRange, &T, &T)) -> T,
        T: Copy,
    {
        if self.timeline != other.timeline {
            return Err(TimeSeriesError::TimelinesDoNotMatch);
        }
        let tl = *self.timeline;
        let data = tl
            .into_iter()
            .zip(self.values.iter())
            .zip(other.values.iter())
            .map(|((a, b), c)| (a, b, c))
            .map(func)
            .collect();
        let ts = TimeSeries::new(self.timeline, data)?;
        Ok(ts)
    }
/// Allows the user to provide a closure that defines the pairwise combination
/// of two time series, plus their timeline
///
/// The closure cannot have side effects (i.e. change the inputs provided). This
/// is to ensure that the `TimeSeries` being operated on, don't change in the process
/// of generating a new `TimeSeries`
///
/// ---
/// ### Example
/// ```
/// use timeseries::{TimeSeries, Timeline, DateRange, Period, Duration};
/// use time::{Date, Month};
///
/// // Create a timeline
/// let from = Date::from_calendar_date(2022, Month::January, 1).unwrap();
/// let dur = Duration::new(0, 0, 2);
/// let dr = DateRange::from_duration(from, dur).unwrap();
/// let tl = Timeline::new(dr, Period::Quarter);
///
/// // Create two timeseries
/// let v1 = vec![1, 2, 3, 4, 1, 2, 3, 4];
/// let ts1 = TimeSeries::new(&tl, v1).unwrap();
/// let v2 = vec![5, 6, 7, 8, 9, 10, 11, 12];
/// let ts2 = TimeSeries::new(&tl, v2).unwrap();
///
/// // Create a date
/// let date = (from + Duration::new(0, 4, 1)).unwrap().primary();
/// // Write a generic function that can be pairwise applied to the elements of a TS and check OK
/// let op = |(t, &a, &b): (DateRange, &i32, &i32)| -> i32 {
///     if t.contains(date) {
///         1000
///     } else if a < 3 {
///         1
///     } else {
///         b + 1
///     }
/// };
/// let ts3 = ts1.apply_with_time(&ts2, op).unwrap();
/// assert_eq!(ts3.value_range(dr).unwrap(), vec![1, 1, 8, 9, 1, 1000, 12, 13]);
///
/// ```
Allows the user to provide a closure that defines the pairwise combination
of two time series, plus their timeline

The closure cannot have side effects . This
is to ensure that the `TimeSeries` being operated on, don't change in the process
of generating a new `TimeSeries`
Allows the user to provide a closure that defines the pairwise combination of two time series plus their timeline The closure cannot have side effects . This is to ensure that the ` TimeSeries ` being operated on don ' t change in the process of generating a new ` TimeSeries `
pub fn apply_with_time<F>(
        &self,
        other: &TimeSeries<'a, T>,
        func: F,
    ) -> Result<TimeSeries<'a, T>, TimeSeriesError>
    where
        F: FnMut((DateRange, &T, &T)) -> T,
        T: Copy,
    {
        if self.timeline != other.timeline {
            return Err(TimeSeriesError::TimelinesDoNotMatch);
        }
        let tl = *self.timeline;
        let data = tl
            .into_iter()
            .zip(self.values.iter())
            .zip(other.values.iter())
            .map(|((a, b), c)| (a, b, c))
            .map(func)
            .collect();
        let ts = TimeSeries::new(self.timeline, data)?;
        Ok(ts)
    }
pub fn apply_with_time < F > ( & self , other : & TimeSeries < ' a , T > , func : F , ) -> Result < TimeSeries < ' a , T > , TimeSeriesError > where F : FnMut ( ( DateRange , & T , & T ) ) -> T , T : Copy , { if self . timeline != other . timeline { return Err ( TimeSeriesError :: TimelinesDoNotMatch ) ; } let tl = * self . timeline ; let data = tl . into_iter ( ) . zip ( self . values . iter ( ) ) . zip ( other . values . iter ( ) ) . map ( | ( ( a , b ) , c ) | ( a , b , c ) ) . map ( func ) . collect ( ) ; let ts = TimeSeries :: new ( self . timeline , data ) ? ; Ok ( ts ) }
Allows the user to provide a closure that defines the pairwise combination
of two time series, plus their timeline
Allows the user to provide a closure that defines the pairwise combination of two time series plus their timeline
&self
other
&TimeSeries<'a, T>
func
F
&self
other
&TimeSeries<'a, T>
func
F
example
```
use timeseries::{TimeSeries, Timeline, DateRange, Period, Duration};
use time::{Date, Month}.

Create a timeline
let from = Date::from_calendar_date(2022, Month::January, 1).unwrap();
let dur = Duration::new(0, 0, 2);
let dr = DateRange::from_duration(from, dur).unwrap();
let tl = Timeline::new(dr, Period::Quarter).



Create a date
let date = (from + Duration::new(0, 4, 1)).unwrap().primary();
Write a generic function that can be pairwise applied to the elements of a TS and check OK
let op = |(t, &a, &b): (DateRange, &i32, &i32)| -> i32 {
if t.contains(date) {
1000
} else if a < 3 {
1
} else {
b + 1
}
};
let ts3 = ts1.apply_with_time(&ts2, op).unwrap();
assert_eq!(ts3.value_range(dr).unwrap(), vec![1, 1, 8, 9, 1, 1000, 12, 13]).


` ` ` use timeseries :: { TimeSeries Timeline DateRange Period Duration } ; use time :: { Date Month } . Create a timeline let from = Date :: from_calendar_date ( 2022 Month :: January 1 ) . unwrap () ; let dur = Duration :: new ( 0 0 2 ) ; let dr = DateRange :: from_duration ( from dur ) . unwrap () ; let tl = Timeline :: new ( dr Period :: Quarter ) . Create a date let date = ( from + Duration :: new ( 0 4 1 )) . unwrap () . primary () ; Write a generic function that can be pairwise applied to the elements of a TS and check OK let op = | ( t &a &b ) : ( DateRange &i32 &i32 ) | - > i32 { if t . contains ( date ) { 1000 } else if a < 3 { 1 } else { b + 1 } } ; let ts3 = ts1 . apply_with_time ( &ts2 op ) . unwrap () ; assert_eq! ( ts3 . value_range ( dr ) . unwrap () vec! [ 1 1 8 9 1 1000 12 13 ] ) .