aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/tainted.lux
blob: ffe128022009008964aa44b3e65aa5ad3bf376bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(;module:
  lux
  (lux (data [product])
       (type opaque)))

(opaque: #export (Tainted a)
  a

  (def: #export taint
    (All [a] (-> a (Tainted a)))
    (|>. @opaque))

  (def: #export trust
    (All [a] (-> (Tainted a) a))
    (|>. @repr)))

(def: #export (validate pred tainted)
  (All [a] (-> (-> a Bool) (Tainted a) (Maybe a)))
  (let [value (trust tainted)]
    (if (pred value)
      (#;Some value)
      #;None)))

(def: #export (sanitize f tainted)
  (All [a] (-> (-> a a) (Tainted a) a))
  (|> tainted trust f))