refactor(router): move fp_utils module to common_utils crate (#391)

Co-authored-by: Arun Raj M <jarnura47@gmail.com>
Co-authored-by: Nishant Joshi <nishant.joshi@juspay.in>
This commit is contained in:
Sanchith Hegde
2023-01-17 13:27:05 +05:30
committed by GitHub
parent 22f32cd4d7
commit d08c35c77c
3 changed files with 12 additions and 6 deletions

View File

@ -1,7 +1,6 @@
pub(crate) mod custom_serde;
pub(crate) mod db_utils;
mod ext_traits;
mod fp_utils;
#[cfg(feature = "kv_store")]
pub(crate) mod storage_partitioning;
@ -9,14 +8,12 @@ pub(crate) mod storage_partitioning;
pub(crate) use common_utils::{
crypto,
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
fp_utils::when,
validation::validate_email,
};
use nanoid::nanoid;
pub(crate) use self::{
ext_traits::{OptionExt, ValidateCall},
fp_utils::when,
};
pub(crate) use self::ext_traits::{OptionExt, ValidateCall};
use crate::consts;
pub mod error_parser {

View File

@ -1,31 +0,0 @@
pub trait Applicative<R> {
type WrappedSelf<T>;
fn pure(v: R) -> Self::WrappedSelf<R>;
}
impl<R> Applicative<R> for Option<R> {
type WrappedSelf<T> = Option<T>;
fn pure(v: R) -> Self::WrappedSelf<R> {
Some(v)
}
}
impl<R, E> Applicative<R> for Result<R, E> {
type WrappedSelf<T> = Result<T, E>;
fn pure(v: R) -> Self::WrappedSelf<R> {
Ok(v)
}
}
// This function allows lazy evaluation of the `f` argument
pub fn when<W: Applicative<(), WrappedSelf<()> = W>, F>(predicate: bool, f: F) -> W
where
F: FnOnce() -> W,
{
if predicate {
f()
} else {
W::pure(())
}
}