1 00:00:00,610 --> 00:00:04,860 Our next set of operators deal with partitioning a sequence, like finding and 2 00:00:04,860 --> 00:00:07,040 extracting a subset of objects. 3 00:00:08,300 --> 00:00:10,050 Let's peek at the documentation real quick. 4 00:00:11,800 --> 00:00:13,680 Partitioning operators. 5 00:00:14,930 --> 00:00:20,210 We've got take, skip, takeWhile, and skipWhile. 6 00:00:21,860 --> 00:00:25,510 So let's switch back to work spaces and 7 00:00:25,510 --> 00:00:27,950 make sure you've got your birds in your console. 8 00:00:27,950 --> 00:00:29,150 I'll make sure I've got mine here. 9 00:00:31,410 --> 00:00:34,090 If we need a certain number of objects from a sequence, 10 00:00:34,090 --> 00:00:35,685 we can use the take operator. 11 00:00:35,685 --> 00:00:41,550 Birds.Take(3). 12 00:00:41,550 --> 00:00:44,530 It's more useful when you order the sequence first. 13 00:00:44,530 --> 00:00:47,645 Let's get the top three birds with the shortest name. 14 00:00:47,645 --> 00:00:52,266 birds.OrderBy b equals 15 00:00:52,266 --> 00:00:56,667 to b.Name.Length and 16 00:00:56,667 --> 00:01:01,300 then we'll take three. 17 00:01:01,300 --> 00:01:03,150 Say we want the next three. 18 00:01:03,150 --> 00:01:04,710 There's an operator for that. 19 00:01:04,710 --> 00:01:07,655 We can skip the first three and then take the next three. 20 00:01:07,655 --> 00:01:13,120 Birds.OrderBy b goes to b. 21 00:01:14,740 --> 00:01:18,620 name .length and 22 00:01:18,620 --> 00:01:22,806 then we'll skip three and 23 00:01:22,806 --> 00:01:27,410 take three and there's the next three. 24 00:01:27,410 --> 00:01:31,650 This can be really helpful when browsing results in a big sequence of objects. 25 00:01:32,960 --> 00:01:37,090 If we had a thousand birds in our list and wanted to look at them all. 26 00:01:37,090 --> 00:01:39,470 It wouldn't be helpful to print out all of them. 27 00:01:39,470 --> 00:01:41,540 You wouldn't have enough space. 28 00:01:41,540 --> 00:01:44,780 So instead we can show birds three at a time and 29 00:01:44,780 --> 00:01:46,880 advance to the list with these operators. 30 00:01:46,880 --> 00:01:48,040 Let's get the next set of three. 31 00:01:50,430 --> 00:01:54,200 Skip six and take three. 32 00:01:55,350 --> 00:01:56,480 Well it only gave us two. 33 00:01:56,480 --> 00:02:00,010 There are no birds left, and it just returned all it had left. 34 00:02:01,130 --> 00:02:04,850 The next two operators are similar but take a predicate. 35 00:02:06,170 --> 00:02:09,920 Take while will produce all the elements up until a condition is met. 36 00:02:11,090 --> 00:02:15,260 It's important to make sure the sequence is ordered correctly because it will 37 00:02:15,260 --> 00:02:19,650 iterate through each element to see if the condition is met, and as soon as it's not, 38 00:02:19,650 --> 00:02:26,228 it stops, birds.TakeWhile(b 39 00:02:26,228 --> 00:02:33,270 Goes to b.Named.Length is less than and six. 40 00:02:34,710 --> 00:02:37,658 Now that doesn't yield anything, what's the first bird in our list? 41 00:02:37,658 --> 00:02:40,052 birds.First. 42 00:02:40,052 --> 00:02:45,240 All right, it's a cardinal and the name Cardinal is eight characters long. 43 00:02:45,240 --> 00:02:48,430 So it fail the condition immediately. 44 00:02:48,430 --> 00:02:51,305 So if we ordered it by length first. 45 00:02:51,305 --> 00:02:59,770 Birds.orderBy b goes to b.name.length. 46 00:02:59,770 --> 00:03:06,125 And then takeWhile b goes to the same thing above. 47 00:03:06,125 --> 00:03:09,300 B.name.length. 48 00:03:09,300 --> 00:03:10,950 Is less than six. 49 00:03:12,960 --> 00:03:17,450 And now we've got three and they all have names that are less than six characters. 50 00:03:19,540 --> 00:03:22,210 There's also the skip while operator. 51 00:03:22,210 --> 00:03:24,530 You should take a moment to pause this video and 52 00:03:24,530 --> 00:03:27,050 write a query using the skip while operator. 53 00:03:27,050 --> 00:03:29,325 That's similar to the one we just wrote. 54 00:03:29,325 --> 00:03:33,290 That skips all the birds until their name is longer than six characters. 55 00:03:35,160 --> 00:03:36,240 How did you do? 56 00:03:36,240 --> 00:03:39,465 All we need to do is change the operator to a skip while. 57 00:03:45,513 --> 00:03:50,560 Partitioning operators are useful in paging results, like with a search engine. 58 00:03:50,560 --> 00:03:53,340 We'll see an example of this with our bird data later on.