compose?
bendn 7 months ago
parent fed52d4 · commit 9f87b48
-rw-r--r--src/lib.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 383bc90..263e455 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -49,3 +49,12 @@ pub trait Bind<Args: Head>: FnMut<Args> + Sized {
}
}
}
+
+pub trait Compose<I, R> {
+ fn compose<T>(self, other: impl FnMut(T) -> I) -> impl FnMut(T) -> R;
+}
+impl<I, R, F: FnMut(I) -> R> Compose<I, R> for F {
+ fn compose<T>(mut self, mut other: impl FnMut(T) -> I) -> impl FnMut(T) -> R {
+ move |x| self(other(x))
+ }
+}