aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/testaceous/main.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/testaceous/main.scala')
-rw-r--r--src/main/scala/testaceous/main.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/scala/testaceous/main.scala b/src/main/scala/testaceous/main.scala
new file mode 100644
index 0000000..ece7056
--- /dev/null
+++ b/src/main/scala/testaceous/main.scala
@@ -0,0 +1,31 @@
+package testaceous
+
+import scala.scalanative.native._
+
+object Main {
+
+ def main(args: Array[String]): Unit = {
+
+ // Parameter definitions
+ val Name = Param[String]('n', 'name)
+ val Value = Param[Int]('v', 'value)
+ val Square = Param[Unit]('s', 'square)
+
+ val params = ParamMap(args: _*)
+
+ // This is the one point where an exception can be thrown
+ val parsed = (Name | (Value & Square)).parse(params)
+
+ // This is guaranteed to be a total function by the typesystem
+ val result = parsed.handle(
+ Name by { name => s"Hello, $name" },
+ (Value & Square) by { product =>
+ val square = product(Value)*product(Value)
+ s"Value squared is $square"
+ }
+ )
+
+ println(result)
+ }
+}
+