Comment

Comment by pkinsky

Java is not a good example of a statically typed language. Null pointer exceptions just don't happen in idiomatic Scala. For example, let's say I have 3 functions a,b and c, each with signature Int => Option[Int]. Any one of these can return Some[Int] or None.

Options, like all collections, can be chained together as such:

   for {
      x <- a(1)
      y <- b(x)
      z <- c(y)
   } yield z
this expression is of type Option[Int], and will never throw a null pointer exception. (Futures can be chained together with identical syntax)
parent pkinsky 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton