Skip to content

Commit

Permalink
series bool
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jul 22, 2023
1 parent 1c229cc commit fdfc6eb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ta_lib/core/src/bool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use crate::series::Series;

impl Series<f64> {
fn compare_series<F>(&self, rhs: &Series<f64>, f: F) -> Series<bool>
where
F: Fn(f64, f64) -> bool,
{
self.zip_with(rhs, |a, b| match (a, b) {
(Some(a_val), Some(b_val)) => Some(f(*a_val, *b_val)),
_ => None,
})
}

fn compare<F>(&self, scalar: f64, f: F) -> Series<bool>
where
F: Fn(f64, f64) -> bool,
Expand Down Expand Up @@ -31,4 +41,28 @@ impl Series<f64> {
pub fn lte(&self, scalar: f64) -> Series<bool> {
self.compare(scalar, |a, b| a <= b)
}

pub fn eq_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a == b)
}

pub fn ne_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a != b)
}

pub fn gt_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a > b)
}

pub fn gte_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a >= b)
}

pub fn lt_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a < b)
}

pub fn lte_series(&self, rhs: &Series<f64>) -> Series<bool> {
self.compare_series(rhs, |a, b| a <= b)
}
}

0 comments on commit fdfc6eb

Please sign in to comment.