pub trait Curry<A, B> {
type Output;
fn curry(self, a: A) -> Self::Output;
}
impl<Func, A, B, Out> Curry<A, B> for Func
where
Func: Fn(A, B) -> Out + 'static,
A: Copy + 'static,
{
type Output = Box<dyn Fn(B) -> Out>;
fn curry(self, a: A) -> Self::Output {
Box::new(move |b: B| self(a, b))
}
}
pub trait Curry2<A, B, C> {
type Output;
fn curry(self, a: A) -> Self::Output;
}
impl<Func, A, B, C, Out> Curry2<A, B, C> for Func
where
Func: Fn(A, B, C) -> Out + 'static,
A: Copy + 'static,
{
type Output = Box<dyn Fn(B, C) -> Out>;
fn curry(self, a: A) -> Self::Output {
Box::new(move |b: B, c: C| self(a, b, c))
}
}
pub trait Curry3<A, B, C, D> {
type Output;
fn curry(self, a: A) -> Self::Output;
}
impl<Func, A, B, C, D, Out> Curry3<A, B, C, D> for Func
where
Func: Fn(A, B, C, D) -> Out + 'static,
A: Copy + 'static,
{
type Output = Box<dyn Fn(B, C, D) -> Out>;
fn curry(self, a: A) -> Self::Output {
Box::new(move |b: B, c: C, d: D| self(a, b, c, d))
}
}
pub trait Curry4<A, B, C, D, E> {
type Output;
fn curry(self, a: A) -> Self::Output;
}
impl<Func, A, B, C, D, E, Out> Curry4<A, B, C, D, E> for Func
where
Func: Fn(A, B, C, D, E) -> Out + 'static,
A: Copy + 'static,
{
type Output = Box<dyn Fn(B, C, D, E) -> Out>;
fn curry(self, a: A) -> Self::Output {
Box::new(move |b: B, c: C, d: D, e: E| self(a, b, c, d, e))
}
}