Scala Coding Editor for Technical Interviews

Running Scala 2.13 - Autocomplete is not available

You should define an object named Solution that extends App, like so:

object Solution extends App { for (i <- 0 until 5) println("Hello, world!") }
Code language: Scala (scala)

Alternatively, you can forego using the App trait helper and define main yourself:

object Solution { def main(args: Array[String]) { println("Hello, world!") } }
Code language: Scala (scala)

We include the Scala testing libraries ScalaCheck and ScalaTest for your convenience. Here’s a quick example of using ScalaTest driven by ScalaCheck generators:

import org.scalatest.prop.GeneratorDrivenPropertyChecks import org.scalatest.{FreeSpec, Matchers} class Testable extends FreeSpec with Matchers with GeneratorDrivenPropertyChecks { def f (x: Int) = Math abs x "f (x) should be >= 0" in forAll ( (x: Int) => f (x) should be >= 0 ) "f (x) should be >= 0 (sometimes!)" in forAll ( (x: Int) => whenever (x != Int.MinValue) (f (x) should be >= 0) ) } object Solution extends App { new Testable().execute() }
Code language: Scala (scala)

Here’s a quick rundown of the Scala libraries we have installed:

libraryDependencies ++= Seq ( "com.chuusai" %% "shapeless" % "2.3.2", "org.scalacheck" %% "scalacheck" % "1.13.4", "org.scalactic" %% "scalactic" % "3.0.1", "org.scalamock" %% "scalamock-scalatest-support" % "3.5.0", "org.scalatest" %% "scalatest" % "3.0.1", "org.scalaz" %% "scalaz-core" % "7.2.12", "org.typelevel" %% "cats" % "0.9.0" )
Code language: Scala (scala)

Additionally, these Java libraries are available. Simply import and fire away:

The google code project page has some useful examples.

  • guava provides immutable collections and other handy utility classes.
  • junit, the gold standard for testing in Java, but quite usable in Scala as well.
import org.junit.Test import org.junit.runner.JUnitCore import org.junit.Assert class TestClass { @Test def testNoop() { Assert.assertTrue(true) } } object Solution { def main(args: Array[String]) { JUnitCore.main("TestClass") } }
Code language: Scala (scala)
  • jMock, a library to assist with mocking in Java. The homepage has some useful examples, and can be adapted for Scala, too.

Try Our Scala Editor