aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/env.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/env.lux')
-rw-r--r--stdlib/source/lux/data/env.lux24
1 files changed, 24 insertions, 0 deletions
diff --git a/stdlib/source/lux/data/env.lux b/stdlib/source/lux/data/env.lux
new file mode 100644
index 000000000..7c29f5833
--- /dev/null
+++ b/stdlib/source/lux/data/env.lux
@@ -0,0 +1,24 @@
+(;module:
+ lux
+ (lux (control functor
+ comonad)))
+
+(type: #export (Env e a)
+ {#env e
+ #value a})
+
+(struct: #export Functor<Env> (All [e] (Functor (Env e)))
+ (def: (map f fa)
+ (update@ #value f fa)))
+
+(struct: #export CoMonad<Env> (All [e] (CoMonad (Env e)))
+ (def: functor Functor<Env>)
+
+ (def: unwrap (get@ #value))
+
+ (def: (split wa)
+ (set@ #value wa wa)))
+
+(def: #export (local change env)
+ (All [e a] (-> (-> e e) (Env e a) (Env e a)))
+ (update@ #env change env))