Scala - Explicitly stating the short circuiting in defining && and || functions -
in scala source code boolean (here), said functions && , || can not defined using => syntax.
// compiler won't build these seemingly more accurate signatures // def ||(x: => boolean): boolean // def &&(x: => boolean): boolean
but can't see problem definitions!
the source code said won't rather can't, maybe have wrongly interpreted it.
if see line 56 of boolean.scala, find explaination ||.
this method uses 'short-circuit' evaluation , behaves if declared
def ||(x: => boolean): boolean
. ifa
evaluatestrue
,true
returned without evaluatingb
.
same && in source code. sum up, can define there no need because of short-circuiting.
Comments
Post a Comment