From 567c71cc4b1d592e27aade5bb18eacef3f533f87 Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Thu, 13 Jul 2023 23:44:17 +0300 Subject: [PATCH] refactor --- ta_lib/core/src/bool.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ta_lib/core/src/bool.rs b/ta_lib/core/src/bool.rs index 6d21330c..fd9d4c7f 100644 --- a/ta_lib/core/src/bool.rs +++ b/ta_lib/core/src/bool.rs @@ -1,27 +1,34 @@ use crate::series::Series; impl Series { + fn compare(&self, scalar: f64, f: F) -> Series + where + F: Fn(f64, f64) -> bool, + { + self.fmap(|x| x.map(|v| f(*v, scalar))) + } + pub fn eq(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v == scalar)) + self.compare(scalar, |a, b| a == b) } pub fn ne(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v != scalar)) + self.compare(scalar, |a, b| a != b) } pub fn gt(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v > scalar)) + self.compare(scalar, |a, b| a > b) } pub fn gte(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v >= scalar)) + self.compare(scalar, |a, b| a >= b) } pub fn lt(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v < scalar)) + self.compare(scalar, |a, b| a < b) } pub fn lte(&self, scalar: f64) -> Series { - self.fmap(|x| x.map(|v| *v <= scalar)) + self.compare(scalar, |a, b| a <= b) } }