Skip to content

Instantly share code, notes, and snippets.

@ivangeorgiev
Last active November 14, 2016 20:47
Show Gist options
  • Save ivangeorgiev/2b4c1920357cb34280f4a82b6b6f6703 to your computer and use it in GitHub Desktop.
Save ivangeorgiev/2b4c1920357cb34280f4a82b6b6f6703 to your computer and use it in GitHub Desktop.

Scala Notes

Tools Install for Linux

Install JDK

sudo apt-get install openjdk-8-jdk

Install sbt

Follow the installation instructions on http://www.scala-sbt.org/release/docs/Setup.html

echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt

Test installation by running sbt about.

  • To run REPL (Run - Evaluate - Print - Loop), furst run sbt than execute the console command. Finish REPL with Ctrl-D.
  • To end sbt, use exit command or Ctrl-D.

IntelliJ IDEA

Basics

// Definition
def x = 3      //> x : => Int
def y = 7      //> y : => Int
def z = x * y  //> z : => Int
z              //> res0: Int = 21

// Definition can have parameters (function)
def increase(i: Int) = i + 1
// Function result type can be defined
def increase(i: Int):Int = i + 1

Primitive types

aa bbb
Int 32 bit integer
Double 64 bit integer
Boolen true or false

// Primitive

// Function can have multiple parameters and call other functions
def square(x: Double) = x * x
def sumOfSquares(x: Double, y: Double) = square(x) + square(y)

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