diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-04-01 11:22:10 +0100 |
---|---|---|
committer | Jon Pretty <jon.pretty@propensive.com> | 2017-04-01 11:22:10 +0100 |
commit | af39cd434103904c9ca97a1e76b5ea6fa9f7418e (patch) | |
tree | 7d094ad79fe277262d8e4880143ad54c5e3f9018 /src/main/scala/testaceous/main.scala | |
download | testaceous-af39cd434103904c9ca97a1e76b5ea6fa9f7418e.tar.gz testaceous-af39cd434103904c9ca97a1e76b5ea6fa9f7418e.tar.bz2 testaceous-af39cd434103904c9ca97a1e76b5ea6fa9f7418e.zip |
Initial checkin of code extracted from Rapture
Diffstat (limited to 'src/main/scala/testaceous/main.scala')
-rw-r--r-- | src/main/scala/testaceous/main.scala | 31 |
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) + } +} + |