Skip to content

Instantly share code, notes, and snippets.

@mgwidmann
Last active March 6, 2018 17:33
Show Gist options
  • Save mgwidmann/43ea07f69d05ccfddd0e8579be748393 to your computer and use it in GitHub Desktop.
Save mgwidmann/43ea07f69d05ccfddd0e8579be748393 to your computer and use it in GitHub Desktop.

Revisions

  1. mgwidmann revised this gist Mar 6, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -16,3 +16,5 @@ def safeOption(shouldBeSafe : Option[String]) : String = {
    }
    safeOption(null) // BOOM java.lang.NullPointerException :(

    // Somes can hold Nones inside them :(, have to use flatMap to remove
    Map("a" -> "b").get("a").map(x => Try(x.toInt).toOption) == Some(None)
  2. mgwidmann revised this gist Mar 5, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -7,12 +7,12 @@ Set(1,2,3).sameElements(Set(3,2,1)) // false
    Some(null).get // No exception :(, Some(null) should result in a None IMO

    // Option objects might be null!!!
    def safeOption(shouldBeSafe : Option[String]) = {
    def safeOption(shouldBeSafe : Option[String]) : String = {
    if (shouldBeSafe.isDefined) {
    return "Yep its safe"
    } else {
    return "No, it was not"
    }
    }
    safeOption(null) // BOOM
    safeOption(null) // BOOM java.lang.NullPointerException :(

  3. mgwidmann revised this gist Mar 5, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wat.scala
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,5 @@ def safeOption(shouldBeSafe : Option[String]) = {
    return "No, it was not"
    }
    }
    safeOption(null) // BOOM

    safeOption(null) // BOOM
  4. mgwidmann revised this gist Mar 5, 2018. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -5,3 +5,14 @@ pow(2, 31).intValue + 1 > 0 // false
    Set(1,2,3).sameElements(Set(3,2,1)) // false

    Some(null).get // No exception :(, Some(null) should result in a None IMO

    // Option objects might be null!!!
    def safeOption(shouldBeSafe : Option[String]) = {
    if (shouldBeSafe.isDefined) {
    return "Yep its safe"
    } else {
    return "No, it was not"
    }
    }

    safeOption(null) // BOOM
  5. mgwidmann revised this gist Mar 5, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -3,3 +3,5 @@
    pow(2, 31).intValue + 1 > 0 // false

    Set(1,2,3).sameElements(Set(3,2,1)) // false

    Some(null).get // No exception :(, Some(null) should result in a None IMO
  6. mgwidmann revised this gist Feb 13, 2018. No changes.
  7. mgwidmann revised this gist Feb 13, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -2,3 +2,4 @@

    pow(2, 31).intValue + 1 > 0 // false

    Set(1,2,3).sameElements(Set(3,2,1)) // false
  8. mgwidmann created this gist Jan 25, 2018.
    4 changes: 4 additions & 0 deletions wat.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    {} + "" == "()" // true

    pow(2, 31).intValue + 1 > 0 // false