aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/data/taint.lux30
1 files changed, 30 insertions, 0 deletions
diff --git a/stdlib/source/lux/data/taint.lux b/stdlib/source/lux/data/taint.lux
new file mode 100644
index 000000000..935d16c72
--- /dev/null
+++ b/stdlib/source/lux/data/taint.lux
@@ -0,0 +1,30 @@
+## Copyright (c) Eduardo Julian. All rights reserved.
+## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+## If a copy of the MPL was not distributed with this file,
+## You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(;module:
+ lux
+ (lux (data [product])))
+
+(type: #export (Tainted a)
+ [a Void])
+
+(def: #export (taint input)
+ (All [a] (-> a (Tainted a)))
+ [input (:! Void [])])
+
+(def: #export (trust input)
+ (All [a] (-> (Tainted a) a))
+ (product;left input))
+
+(def: #export (validate pred input)
+ (All [a] (-> (-> a Bool) (Tainted a) (Maybe a)))
+ (let [value (product;left input)]
+ (if (pred value)
+ (#;Some value)
+ #;None)))
+
+(def: #export (sanitize f input)
+ (All [a] (-> (-> a a) (Tainted a) a))
+ (|> input product;left f))