mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
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:
@ -1,6 +1,13 @@
|
|||||||
|
//! Functional programming utilities
|
||||||
|
|
||||||
|
/// The Applicative trait provides a pure behavior,
|
||||||
|
/// which can be used to create values of type f a from values of type a.
|
||||||
pub trait Applicative<R> {
|
pub trait Applicative<R> {
|
||||||
|
/// The Associative type acts as a (f a) wrapper for Self.
|
||||||
type WrappedSelf<T>;
|
type WrappedSelf<T>;
|
||||||
|
|
||||||
|
/// Applicative::pure(_) is abstraction with lifts any arbitrary type to underlying higher
|
||||||
|
/// order type
|
||||||
fn pure(v: R) -> Self::WrappedSelf<R>;
|
fn pure(v: R) -> Self::WrappedSelf<R>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +25,8 @@ impl<R, E> Applicative<R> for Result<R, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function allows lazy evaluation of the `f` argument
|
/// This function wraps the evaluated result of `f` into current context,
|
||||||
|
/// based on the condition provided into the `predicate`
|
||||||
pub fn when<W: Applicative<(), WrappedSelf<()> = W>, F>(predicate: bool, f: F) -> W
|
pub fn when<W: Applicative<(), WrappedSelf<()> = W>, F>(predicate: bool, f: F) -> W
|
||||||
where
|
where
|
||||||
F: FnOnce() -> W,
|
F: FnOnce() -> W,
|
||||||
@ -7,6 +7,7 @@ pub mod crypto;
|
|||||||
pub mod custom_serde;
|
pub mod custom_serde;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod ext_traits;
|
pub mod ext_traits;
|
||||||
|
pub mod fp_utils;
|
||||||
pub mod pii;
|
pub mod pii;
|
||||||
pub mod validation;
|
pub mod validation;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
pub(crate) mod custom_serde;
|
pub(crate) mod custom_serde;
|
||||||
pub(crate) mod db_utils;
|
pub(crate) mod db_utils;
|
||||||
mod ext_traits;
|
mod ext_traits;
|
||||||
mod fp_utils;
|
|
||||||
|
|
||||||
#[cfg(feature = "kv_store")]
|
#[cfg(feature = "kv_store")]
|
||||||
pub(crate) mod storage_partitioning;
|
pub(crate) mod storage_partitioning;
|
||||||
@ -9,14 +8,12 @@ pub(crate) mod storage_partitioning;
|
|||||||
pub(crate) use common_utils::{
|
pub(crate) use common_utils::{
|
||||||
crypto,
|
crypto,
|
||||||
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
|
ext_traits::{ByteSliceExt, BytesExt, Encode, StringExt, ValueExt},
|
||||||
|
fp_utils::when,
|
||||||
validation::validate_email,
|
validation::validate_email,
|
||||||
};
|
};
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
|
|
||||||
pub(crate) use self::{
|
pub(crate) use self::ext_traits::{OptionExt, ValidateCall};
|
||||||
ext_traits::{OptionExt, ValidateCall},
|
|
||||||
fp_utils::when,
|
|
||||||
};
|
|
||||||
use crate::consts;
|
use crate::consts;
|
||||||
|
|
||||||
pub mod error_parser {
|
pub mod error_parser {
|
||||||
|
|||||||
Reference in New Issue
Block a user