Hacker News new | past | comments | ask | show | jobs | submit login

Yes, I posted before seeing the other comments, the problem is that you can't force lazy evaluation of the function arguments in javascript. On the other hands it can be as easily written in languages that support it, for example in Scala:

  def and(a: Boolean, b: =>Boolean) = if (a) b else false
And with Scala it can be easily made to work as an infix operator:

  implicit class AndOp(a: Boolean) {
    def and(b: =>Boolean) = if (a) b else false
  }
Verification:

  def foo = { println("foo"); false }

  scala> false and foo
  res2: Boolean = false

  scala> true and foo
  foo
  res3: Boolean = false



Hey, neat. Now can you rewrite the code you call and with, inside of and? I kid.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: