Skip to content

Instantly share code, notes, and snippets.

@jseteny
Created July 6, 2020 12:15
Show Gist options
  • Save jseteny/483a40d8805a23ea81488ce8e5f7a754 to your computer and use it in GitHub Desktop.
Save jseteny/483a40d8805a23ea81488ce8e5f7a754 to your computer and use it in GitHub Desktop.
{
trait QList[+A]{
def ::[B >: A](head: B): QList[B] = new ::(head, this)
}
case class ::[+A](head: A, tail: QList[A]) extends QList[A]
object QNil extends QList[Nothing]
}
// defined trait QList
// defined class ::
// defined object QNil
1 :: QNil
// res9: QList[Int] = 1 :: ammonite.$sess.cmd8$QNil$@f2d890c
1 :: QNil match {
case QNil => 1
case _ => 0
}
// res10: Int = 0
QNil match {
case QNil => 1
case _ => 0
}
// res11: Int = 1
2 :: QNil match {
case a::_ => a
case _ => 0
}
// res12: Int = 2
1::2::3::QNil
// res13: QList[Int] = 1 :: 2 :: 3 :: ammonite.$sess.cmd8$QNil$@f2d890c
"1"::"2"::"3"::QNil
// res14: QList[String] = "1" :: "2" :: "3" :: ammonite.$sess.cmd8$QNil$@f2d890c
@jseteny
Copy link
Author

jseteny commented Jul 6, 2020

To try it yourself there is a so called one-click Scala install option to consider:
https://www.scala-lang.org/2020/06/29/one-click-install.html

... will install all the following software, if not yet installed:

a JDK
the build tools sbt and mill
the Ammonite enhanced REPL
scalafmt, the Scala formatter
the coursier CLI, to install further Scala-based applications
the scala and scalac command-line tools
With all those installed, we are ready to go! Later, cs update can be used to update the installation.

For power users, the cs setup command offers more configuration options, such as a non-interactive mode.

If you need one or more very simple VM for your experiment(s) you may try:
https://multipass.run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment