aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/testaceous/main.scala
blob: ece7056b542b4d1459d45e533f27ddd1099216d4 (plain) (blame)
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
27
28
29
30
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)
  }
}