logoalt Hacker News

lmmtoday at 10:12 AM1 replyview on HN

Here's my effort: https://m50d.github.io/2013/01/16/generic-contexts


Replies

amenghratoday at 10:55 AM

From the very beginning of the article (level 1), I don't see what's wrong with code that looks like the following. Early return seems to fix the "typing this makes me feel ill" part? To me, the following code seems perfectly readable without requiring the reader to know about function composition.

  def doFunctionsInSequence1(): Option[Set[Int]] = {
    val r1 = f1(null)
    if(r1.isEmpty) {
      return None
    }

    val r2 = f2(r1.get)
    if(r2.isEmpty) {
      return None
    }

    return f3(r2.get)
  }
show 1 reply