Skip to content

Instantly share code, notes, and snippets.

@adekunleba
adekunleba / cheatsheet.scala
Last active August 22, 2018 16:03
Scala Cheatsheets
//Extracting Values from Optional in Scala
//a. This works well if you have a defined value for your else
val value = Some("Data")
value.getOrElse("No Value")
//b Using match you can extract the value and do anything you want with it
value match {
case Some(i) => println(s"There is a value $i")
case _ => println("There is nothing in value")
}
@adekunleba
adekunleba / DistanceMetrics.scala
Last active August 17, 2018 11:47
Basic Distance Calculation of two Vectors with Scala
import math._
object DistanceMetrics {
/**
* distance method helps get the Euclidean Distance between two vectors
* Euclidean Distance tests the space betweeen two Vectors and the result is
* between 0 and 2 where:
* 0 means the space between them is 0
* 2 meanns the space between the two vector is at maximum
* @param xs