aboutsummaryrefslogtreecommitdiff
path: root/lib/SATS/valid.sats
diff options
context:
space:
mode:
authorXander <xander@biltopia.org>2023-08-19 19:47:17 +0200
committerXander <xander@biltopia.org>2023-08-19 19:47:17 +0200
commita76c89dc3932f0b5e60ff871b08f4bc745727ae4 (patch)
tree9b374611b349b922f2cc9f6194cb9d426f6aa7c2 /lib/SATS/valid.sats
parentfcf755d4f03f6fba974d11307659e2e96f9696e7 (diff)
downloadats-os-a76c89dc3932f0b5e60ff871b08f4bc745727ae4.tar.xz
ats-os-a76c89dc3932f0b5e60ff871b08f4bc745727ae4.zip
made valid type a viewtype
Diffstat (limited to 'lib/SATS/valid.sats')
-rw-r--r--lib/SATS/valid.sats15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/SATS/valid.sats b/lib/SATS/valid.sats
index e3841e0..83081fe 100644
--- a/lib/SATS/valid.sats
+++ b/lib/SATS/valid.sats
@@ -3,16 +3,21 @@
// It's a replacement of Optional, but can be allocated on stack, so no heap allocaton needed.
// When unvalid, it should be not possible to get unvalid value, thats why abstract type is used.
// bool b: true means valid, false unvalid
-abst@ype valid(a:t@ype,b:bool) = (a,bool b)
+absviewt@ype valid(a:viewt@ype,b:bool) = (a,bool b)
-typedef Valid(a:t@ype) = [b : bool] valid(a,b)
+viewtypedef Valid(a:viewt@ype) = [b : bool] valid(a,b)
// Wraps valid value.
-fn {a:t@ype} create_valid(value : a) : valid(a,true)
+fn {a:viewt@ype} create_valid(a) : valid(a,true)
// Creates unvalid type.
-fn {a:t@ype} create_unvalid() : valid(a,false)
+fn {a:viewt@ype} create_unvalid() : valid(a,false)
// Only function that allows getting value. Only accepts valid values.
-fn {a:t@ype} unwrap_valid(valid(a,true)) : a
+fn {a:viewt@ype} unwrap_valid(valid(a,true)) : a
+
+castfn destroy_unvalid{a:viewt@ype}(valid(a,false)) : void
+
+// Check if value is valid
+fn{a:viewt@ype} is_valid{b:bool}(!valid(a,b)) : bool b