Skip to content

Commit

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

impl Series<f64> {
fn compare<F>(&self, scalar: f64, f: F) -> Series<bool>
where
F: Fn(f64, f64) -> bool,
{
self.fmap(|x| x.map(|v| f(*v, scalar)))
}

pub fn eq(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v == scalar))
self.compare(scalar, |a, b| a == b)
}

pub fn ne(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v != scalar))
self.compare(scalar, |a, b| a != b)
}

pub fn gt(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v > scalar))
self.compare(scalar, |a, b| a > b)
}

pub fn gte(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v >= scalar))
self.compare(scalar, |a, b| a >= b)
}

pub fn lt(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v < scalar))
self.compare(scalar, |a, b| a < b)
}

pub fn lte(&self, scalar: f64) -> Series<bool> {
self.fmap(|x| x.map(|v| *v <= scalar))
self.compare(scalar, |a, b| a <= b)
}
}

0 comments on commit 567c71c

Please sign in to comment.