Skip to content

Instantly share code, notes, and snippets.

View rdecaire's full-sized avatar

Robert DeCaire rdecaire

  • Inflection Group
  • Toronto
View GitHub Profile
val p: Option[Int] = None
p.get
// java.util.NoSuchElementException: None.get
val o1 = Some("hello")
val o2 = None
val o3 = Some("world")
val o4 = for {
a <- o1
b <- o2
c <- o3
val o1 = Some("hello")
val o2 = None
val o3 = o1.flatMap(a => o2.map(b => a + " " + b))
// o3: Option[String] = None
val o1 = Some("hello")
val o2 = Some("world")
val o3 = o1.flatMap(a => o2.map(b => a + " " + b))
// o3: Option[String] = Some(hello world)
val op = Option("hello")
// op: Option[String] = Some(hello)
val some = Some("hello")
// some: Some[String] = Some(hello)
val none = None
// none: None.type = None
// given some function 'combine' that can take three values and combine them into one:
def combine(a: A, b: A, c: A): A
// this for-comprehension
for {
a <- m1
b <- m2
c <- m3
} yield combine(a,b,c)
val list = List(1,2)
val mappedList = list.map(makeListOfDoubles)
// mappedList: List[List[Double]] = List(List(1.0), List(2.0))
val list = List.apply(1)
// list: List[Int] = List(1)
val list2 = List(1)
// list2: List[Int] = List(1)
def makeListofDoubles(int: Int): List[Double] = {
List(int.toDouble)
}

Keybase proof

I hereby claim:

  • I am emotecontrol on github.
  • I am robertdecaire (https://keybase.io/robertdecaire) on keybase.
  • I have a public key ASDrQ6TveXWU5zeDDjjyV8BqGVR0m2CMzwQ77wtuVgBgJwo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am emotecontrol on github.
  • I am robertdecaire (https://keybase.io/robertdecaire) on keybase.
  • I have a public key whose fingerprint is 0111 0BF6 81DD 2278 BF23 AC55 EE56 C23B 9BC6 6AC9

To claim this, I am signing this object: