aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/type/variance.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/meta/type/variance.lux')
-rw-r--r--stdlib/source/library/lux/meta/type/variance.lux45
1 files changed, 45 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/type/variance.lux b/stdlib/source/library/lux/meta/type/variance.lux
new file mode 100644
index 000000000..ac7e120d4
--- /dev/null
+++ b/stdlib/source/library/lux/meta/type/variance.lux
@@ -0,0 +1,45 @@
+(.require
+ [library
+ [lux (.except)
+ [meta
+ ["[0]" symbol]]]])
+
+(type .public (Co it)
+ (-> Any it))
+
+(type .public (Contra it)
+ (-> it Any))
+
+(type .public (In it)
+ (-> it it))
+
+(type .public (Mutable r w)
+ (Primitive "#Mutable" [(-> w r)]))
+
+(with_template [<name> <type>]
+ [(def .public <name>
+ (template (<name> it)
+ [((.is (.All (_ r w) <type>)
+ (.|>> .as_expected))
+ it)]))]
+
+ [read (.-> (..Mutable r w) r)]
+ [write (.-> w (..Mutable r w))]
+ )
+
+(type .public (Read_Only a)
+ (Mutable a Nothing))
+
+(type .public (Write_Only a)
+ (Mutable Any a))
+
+(with_template [<name> <type>]
+ [(def .public <name>
+ (template (<name> it)
+ [((.is (.All (_ r w) <type>)
+ (.|>>))
+ it)]))]
+
+ [read_only (.-> (..Mutable r w) (..Read_Only r))]
+ [write_only (.-> (..Mutable r w) (..Write_Only w))]
+ )