WEBVTT

00:00.820 --> 00:01.390
Hi everyone.

00:01.390 --> 00:02.740
Welcome back to this tutorial.

00:02.740 --> 00:09.640
In this tutorial we will talk about short circuiting and how it's applicable in the stream's context.

00:10.000 --> 00:14.830
I would like to give you a general idea about what is short circuiting.

00:14.830 --> 00:16.480
This is not a new concept.

00:16.480 --> 00:22.630
Any experienced developer would have come across this concept at some point in their experience.

00:23.780 --> 00:26.900
I would like to explain this using a couple of examples here.

00:26.930 --> 00:33.020
The first example here we are performing an operation and the second example here we are performing

00:33.020 --> 00:35.180
a or operation.

00:35.180 --> 00:37.100
Let's take a look at the first example.

00:37.100 --> 00:43.100
Here we have two booleans here and then we are performing A and operation.

00:43.100 --> 00:50.480
If the first boolean evaluates to false, then the second Boolean expression, whatever that is.

00:50.480 --> 00:59.000
After this ampersand won't get executed because as part of the and operation, if one of the condition

00:59.000 --> 01:05.020
executes to false, then the whole if statement is evaluated to false.

01:05.030 --> 01:08.490
This concept is called short circuiting.

01:08.510 --> 01:12.290
Let's take a look at the example two, which is a or operation.

01:12.290 --> 01:20.450
If the first condition evaluates to true, then any condition after the Or operation won't get executed.

01:20.450 --> 01:27.510
Because for our operation, if any one of the statement is true, then the whole if statement is going

01:27.510 --> 01:30.240
to be evaluated to true.

01:30.270 --> 01:35.080
This concept is again called the short circuiting.

01:35.100 --> 01:39.750
Let's take a look at how short circuiting is applicable in the streams API.

01:40.530 --> 01:47.070
So far Streams API, we have seen a lot of different stream functions until now, but the ones that

01:47.070 --> 01:54.330
are listed here are the short circuit functions because these functions does not have to iterate the

01:54.330 --> 01:58.520
whole stream to get you the result that you are looking for.

01:58.530 --> 02:07.230
So the stream API that uses a concept of short circuiting or limit find first, find any.

02:07.380 --> 02:09.510
Any match all match.

02:09.510 --> 02:10.650
None match.

02:10.680 --> 02:13.530
So I'm just going to read out whatever that is given here.

02:13.530 --> 02:21.630
All these function does not have to iterate the whole stream to evaluate the result.

02:21.660 --> 02:27.330
Let's take a look at the example of limit and understand more on this topic.

02:28.050 --> 02:29.310
I'm going to go back to IntelliJ.

02:31.280 --> 02:32.090
Bentley, J.

02:33.590 --> 02:36.140
Let me close close this one and then open it from the beginning.

02:36.140 --> 02:42.400
I'm going to open the stream's limit skip example, which we did in one of the previous tutorial.

02:42.410 --> 02:46.400
If you take a look at it, I'm going to put this in presentation mode.

02:48.850 --> 02:53.970
So for the limit, the input has like five elements in it, right?

02:53.980 --> 02:58.720
But still here we are limiting the value to three.

02:58.870 --> 03:06.670
What does it mean is that here we will just process the first three elements and then give you the result

03:06.670 --> 03:07.860
which you are looking for.

03:07.870 --> 03:13.400
Here we are performing the summation of all the elements that are being parsed as part of the string.

03:13.420 --> 03:16.810
Basically with limit, it is not going to parse all the elements.

03:16.810 --> 03:23.850
It is going to parse the elements, whatever that is being passed as an input to this limit function.

03:23.860 --> 03:29.830
This concept is called short circuiting in Streams API.

03:30.720 --> 03:33.960
So this is all about short circuiting.

03:34.560 --> 03:37.090
With this, we came to the end of this tutorial.

03:37.110 --> 03:38.370
Thank you for watching.
