summaryrefslogtreecommitdiff
path: root/src/mode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mode.rs')
-rw-r--r--src/mode.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/mode.rs b/src/mode.rs
new file mode 100644
index 0000000..3825e31
--- /dev/null
+++ b/src/mode.rs
@@ -0,0 +1,66 @@
+pub trait Mode {
+ type Output<T>;
+
+ fn bind<T, F>(f: F) -> Self::Output<T>
+ where
+ F: FnOnce() -> T;
+
+ fn map<T, U, F>(t: Self::Output<T>, f: F) -> Self::Output<U>
+ where
+ F: FnOnce(T) -> U;
+
+ fn combine<T, U, V, F>(t: Self::Output<T>, u: Self::Output<U>, f: F) -> Self::Output<V>
+ where
+ F: FnOnce(T, U) -> V;
+}
+
+pub struct Emit;
+
+impl Mode for Emit {
+ type Output<T> = T;
+
+ fn bind<T, F>(f: F) -> Self::Output<T>
+ where
+ F: FnOnce() -> T,
+ {
+ f()
+ }
+
+ fn map<T, U, F>(t: Self::Output<T>, f: F) -> Self::Output<U>
+ where
+ F: FnOnce(T) -> U,
+ {
+ f(t)
+ }
+
+ fn combine<T, U, V, F>(t: Self::Output<T>, u: Self::Output<U>, f: F) -> Self::Output<V>
+ where
+ F: FnOnce(T, U) -> V,
+ {
+ f(t, u)
+ }
+}
+
+pub struct Check;
+
+impl Mode for Check {
+ type Output<T> = ();
+
+ fn bind<T, F>(_: F) -> Self::Output<T>
+ where
+ F: FnOnce() -> T,
+ {
+ }
+
+ fn map<T, U, F>(_: Self::Output<T>, _: F) -> Self::Output<U>
+ where
+ F: FnOnce(T) -> U,
+ {
+ }
+
+ fn combine<T, U, V, F>(_: Self::Output<T>, _: Self::Output<U>, _: F) -> Self::Output<V>
+ where
+ F: FnOnce(T, U) -> V,
+ {
+ }
+}