Hi everyone.
Welcome back to this tutorial.
In this tutorial we will talk about short circuiting and how it's applicable in the stream's context.
I would like to give you a general idea about what is short circuiting.
This is not a new concept.
Any experienced developer would have come across this concept at some point in their experience.
I would like to explain this using a couple of examples here.
The first example here we are performing an operation and the second example here we are performing
a or operation.
Let's take a look at the first example.
Here we have two booleans here and then we are performing A and operation.
If the first boolean evaluates to false, then the second Boolean expression, whatever that is.
After this ampersand won't get executed because as part of the and operation, if one of the condition
executes to false, then the whole if statement is evaluated to false.
This concept is called short circuiting.
Let's take a look at the example two, which is a or operation.
If the first condition evaluates to true, then any condition after the Or operation won't get executed.
Because for our operation, if any one of the statement is true, then the whole if statement is going
to be evaluated to true.
This concept is again called the short circuiting.
Let's take a look at how short circuiting is applicable in the streams API.
So far Streams API, we have seen a lot of different stream functions until now, but the ones that
are listed here are the short circuit functions because these functions does not have to iterate the
whole stream to get you the result that you are looking for.
So the stream API that uses a concept of short circuiting or limit find first, find any.
Any match all match.
None match.
So I'm just going to read out whatever that is given here.
All these function does not have to iterate the whole stream to evaluate the result.
Let's take a look at the example of limit and understand more on this topic.
I'm going to go back to IntelliJ.
Bentley, J.
Let me close close this one and then open it from the beginning.
I'm going to open the stream's limit skip example, which we did in one of the previous tutorial.
If you take a look at it, I'm going to put this in presentation mode.
So for the limit, the input has like five elements in it, right?
But still here we are limiting the value to three.
What does it mean is that here we will just process the first three elements and then give you the result
which you are looking for.
Here we are performing the summation of all the elements that are being parsed as part of the string.
Basically with limit, it is not going to parse all the elements.
It is going to parse the elements, whatever that is being passed as an input to this limit function.
This concept is called short circuiting in Streams API.
So this is all about short circuiting.
With this, we came to the end of this tutorial.
Thank you for watching.