From fdfc6ebb2086e8a9cf922e6d2b13be0c134611e0 Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Sat, 22 Jul 2023 16:56:53 +0300 Subject: [PATCH] series bool --- ta_lib/core/src/bool.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ta_lib/core/src/bool.rs b/ta_lib/core/src/bool.rs index fd9d4c7f..6b8d52ef 100644 --- a/ta_lib/core/src/bool.rs +++ b/ta_lib/core/src/bool.rs @@ -1,6 +1,16 @@ use crate::series::Series; impl Series { + fn compare_series(&self, rhs: &Series, f: F) -> Series + 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(&self, scalar: f64, f: F) -> Series where F: Fn(f64, f64) -> bool, @@ -31,4 +41,28 @@ impl Series { pub fn lte(&self, scalar: f64) -> Series { self.compare(scalar, |a, b| a <= b) } + + pub fn eq_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a == b) + } + + pub fn ne_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a != b) + } + + pub fn gt_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a > b) + } + + pub fn gte_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a >= b) + } + + pub fn lt_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a < b) + } + + pub fn lte_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a <= b) + } }