ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 기본 사용법
    scala/scala-cli 2024. 1. 27. 20:29

    https://scala-cli.virtuslab.org/ 사용법 소개

    (scala 2.13 을 사용 중인데, scala 3 survey 에 scala-cli 를 활용해 보았다.)

    Run scripts

    hello.sc

    def helloMessage(names: Seq[String]) = names match
      case Nil =>
        "Hello!"
      case names =>
        names.mkString("Hello: ", ", ", "!")
    
    println(helloMessage(args.toSeq))
    println(os.pwd)

     

    실행

    scala-cli \
      --jvm 21 \
      --dep com.lihaoyi::os-lib:0.9.0 \
      hello.sc -- James Candy

     

     

     

    Run scala code

    Test.scala (scala-3.3.1)

    //> using dep com.lihaoyi::os-lib:0.9.3
    //> using dep com.softwaremill.ox::core:0.0.18
    
    import ox.par
    
    object Test {
      def computation1: Int =
        Thread.sleep(2000)
        1
    
      def computation2: String =
        Thread.sleep(1000)
        "2"
    
      def main(args: Array[String]): Unit =
        val result: (Int, String) = par(computation1)(computation2)
    
        println(result)
    }

     

    실행

    scala-cli run --jvm 21 Test.scala

    댓글

Designed by Tistory.