Filter
Filter
2
00:00:05,820 --> 00:00:09,040
the most popular functions out there are called Filter.
3
00:00:09,090 --> 00:00:14,880
As I mentioned before there are a lot more than three functions such as filter Gnab
and redos in a functional
4
00:00:14,880 --> 00:00:15,690
programming world.
5
00:00:15,690 --> 00:00:21,240
However the purpose isn't to memorize everything it needs to understand what goes
under the hood.
6
00:00:21,330 --> 00:00:24,170
So no one becomes a zombie which has been for a while.
7
00:00:24,210 --> 00:00:27,600
When I first learned about functional programming today in this lesson let's take a
look at one of the
8
00:00:27,600 --> 00:00:34,170
most popular functions call filters which is used to filter an array and see how
they are treated and
9
00:00:34,170 --> 00:00:36,940
also learn how to create or own custom filter.
10
00:00:37,140 --> 00:00:39,180
Let's get started.
11
00:00:47,320 --> 00:00:49,050
Welcome to Lawrence bell.
12
00:00:49,090 --> 00:00:55,670
Today let's talk about philtre which is part of function programming is a filter of
functions.
13
00:00:56,020 --> 00:01:00,340
You often use my app on years and so have developers to get things done.
14
00:01:00,340 --> 00:01:04,930
For example if you an array for one hundred if you want all of them get the even
numbers you can use
15
00:01:04,930 --> 00:01:09,890
as filter functions to get even numbers in one line of code with one line of code.
16
00:01:09,990 --> 00:01:10,320
OK.
17
00:01:10,330 --> 00:01:11,400
That is powerful.
18
00:01:11,620 --> 00:01:17,980
Well but let's get to your pass by the way people use this kind of functions.
19
00:01:18,700 --> 00:01:23,190
People use all kind of all kinds of function without knowing the behind the form.
20
00:01:23,220 --> 00:01:28,300
And it's important to understand what the heck's going on when you're using this
function because every
21
00:01:28,300 --> 00:01:33,550
time when you're using functions you don't know about the behind implementation
then it's not good for
22
00:01:33,550 --> 00:01:38,020
you because sometimes you want to create your own function in the feature dependent
can depending on
23
00:01:38,020 --> 00:01:39,030
the context.
24
00:01:39,100 --> 00:01:44,810
If you don't know how to create a function using a function programming approach
well you're stuck or
25
00:01:44,950 --> 00:01:51,120
you become a zombie you just become a passive just using code written by somebody
else.
26
00:01:51,220 --> 00:01:51,460
Right.
27
00:01:51,470 --> 00:01:56,080
Sometimes that's good as long as you understand the principle behind it.
28
00:01:56,170 --> 00:02:02,020
Ok so today let's talk about how to create our own custom filter and understand
what the heck's going
29
00:02:02,020 --> 00:02:03,060
on underneath.
30
00:02:03,070 --> 00:02:03,560
OK.
31
00:02:04,000 --> 00:02:06,790
So let's begin with a non functional way to get things done.
32
00:02:06,790 --> 00:02:11,020
So if you want to get even numbers this is how you did in the past.
33
00:02:11,020 --> 00:02:17,770
You get the number from 1 to 4 and look from 1 to 10 and then if it was applied to
your Pantages even
34
00:02:17,770 --> 00:02:18,560
number re.
35
00:02:18,660 --> 00:02:19,110
OK.
36
00:02:19,210 --> 00:02:22,930
But when it comes to functional programming I think I mentioned you do last time.
37
00:02:22,930 --> 00:02:31,600
You can do something like this array 9:59 filter and you get the number number
divided by two you know.
38
00:02:31,720 --> 00:02:35,030
And now this thing returns a value only even numbers.
39
00:02:35,160 --> 00:02:35,920
OK.
40
00:02:36,580 --> 00:02:37,340
You don't believe me.
41
00:02:37,350 --> 00:02:38,950
We'll see if.
42
00:02:38,980 --> 00:02:40,450
Let's find out how that works.
43
00:02:41,890 --> 00:02:43,940
You see right there.
44
00:02:44,040 --> 00:02:45,330
Yeah so.
45
00:02:45,490 --> 00:02:48,770
So you might wonder what the heck's going on.
46
00:02:48,940 --> 00:02:49,270
OK.
47
00:02:49,300 --> 00:02:53,670
That is a question I'm to talk about how to get things going and what is.
48
00:02:54,110 --> 00:02:56,130
How how to make it happen.
49
00:02:56,250 --> 00:03:02,500
So apparently you're entering what Clojure block to this filter function.
50
00:03:02,930 --> 00:03:09,440
And so let's take a look at it first ball we build for replicate how to get things
done like this.
51
00:03:09,480 --> 00:03:10,050
OK.
52
00:03:10,330 --> 00:03:11,850
This is very powerful.
53
00:03:11,860 --> 00:03:12,670
How many lines of this.
54
00:03:12,670 --> 00:03:14,240
One two three four five.
55
00:03:14,290 --> 00:03:16,500
You can get this thing done with one lenticular.
56
00:03:16,620 --> 00:03:17,130
OK.
57
00:03:17,350 --> 00:03:18,760
That is a power filter.
58
00:03:18,910 --> 00:03:20,570
And we'll take a look at more and more.
59
00:03:20,740 --> 00:03:25,870
So now let's learn how to create our own custom filter to understand what the
heck's going on.
60
00:03:25,870 --> 00:03:35,960
So for example let's say we have an array mide array Lissi or high school college
we have AAA Biondi.
61
00:03:36,190 --> 00:03:37,730
OK can be anything you can be number.
62
00:03:37,730 --> 00:03:42,300
It can be true it can be false you can be any type of any type of data.
63
00:03:42,340 --> 00:03:45,030
It doesn't really matter but you want to filter out the data.
64
00:03:45,160 --> 00:03:50,620
Let's say you want you want to get the value of Ezola you don't want to get B or D
because my mom only
65
00:03:50,620 --> 00:03:52,140
wanted to see A's only.
66
00:03:52,180 --> 00:03:53,650
So you want only get A's.
67
00:03:53,710 --> 00:03:54,120
OK.
68
00:03:54,130 --> 00:03:54,970
So how to do that.
69
00:03:55,000 --> 00:04:01,540
Well let's first begin with the nonfunctional way to appreciate functional way
after.
70
00:04:01,600 --> 00:04:06,550
So if you want to only get to a value within an array Well you probably do.
71
00:04:06,640 --> 00:04:13,480
Let's create a function array call happy great empty string value and then you
probably do something
72
00:04:13,480 --> 00:04:16,460
like this for grading.
73
00:04:16,540 --> 00:04:23,990
Recent great reverse this and that if is great is a pen that is grave a pen grade
to this happy grade
74
00:04:24,700 --> 00:04:27,020
and I've done my mama's The happy.
75
00:04:27,070 --> 00:04:27,480
OK.
76
00:04:27,550 --> 00:04:30,140
So of course D-NV are not.
77
00:04:30,290 --> 00:04:31,330
So it's going to print.
78
00:04:31,330 --> 00:04:32,750
My mama is not happy.
79
00:04:33,010 --> 00:04:33,740
OK.
80
00:04:34,150 --> 00:04:39,900
So if you now print happy grade on the bottom you'll see that it's a right there.
81
00:04:39,970 --> 00:04:40,360
OK.
82
00:04:40,390 --> 00:04:44,610
That is how you did in the past using imperative nonfunctional way.
83
00:04:44,680 --> 00:04:49,140
And again what you want to do is you will get things done and one line of code.
84
00:04:49,370 --> 00:04:49,920
OK.
85
00:04:50,140 --> 00:04:52,160
One single line of code
86
00:04:54,830 --> 00:04:56,530
call let's.
87
00:04:56,590 --> 00:04:59,900
Let's see how good it had to get this done.
88
00:05:00,000 --> 00:05:07,860
So let's talk about the functional way functionally First of all just like here
we're going to design
89
00:05:07,860 --> 00:05:11,160
a closer blog that's going to enter to the filter.
90
00:05:11,200 --> 00:05:12,930
We're not going to design a filter first.
91
00:05:13,170 --> 00:05:15,690
We're going to design these Clojure block first.
92
00:05:15,720 --> 00:05:16,150
OK.
93
00:05:16,200 --> 00:05:17,530
And you'll see what's happening.
94
00:05:17,670 --> 00:05:22,140
And then we're going to enter the Clojure blunt into this filter function that we
can design soon custom
95
00:05:22,140 --> 00:05:23,860
filter so visible.
96
00:05:23,910 --> 00:05:27,110
You can create Voller is mom happy kid.
97
00:05:27,170 --> 00:05:30,500
This is a closer block by the way it's going to enter string value.
98
00:05:30,600 --> 00:05:31,620
OK.
99
00:05:31,920 --> 00:05:33,720
No big deal or anything like that.
100
00:05:33,930 --> 00:05:38,800
And then it's going to be going to.
101
00:05:38,970 --> 00:05:39,420
There.
102
00:05:39,460 --> 00:05:46,370
And this is called listing grade the first parameter returned grade equals a.
103
00:05:46,540 --> 00:05:47,760
OK.
104
00:05:48,640 --> 00:05:55,570
So now if the great grade is a it's going to retire.
105
00:05:55,610 --> 00:05:58,480
So if you raise a rate it's going to turn what.
106
00:05:58,490 --> 00:06:00,280
True is B.
107
00:06:00,590 --> 00:06:02,020
B equals equals a.
108
00:06:02,060 --> 00:06:05,170
No it's going to be true or false or this is a shorter way of saying it.
109
00:06:05,300 --> 00:06:08,300
OK so now what's happening is you can do
110
00:06:11,410 --> 00:06:21,510
is mom happy you can enter one let's enter a happy and third be right there.
111
00:06:21,550 --> 00:06:23,850
You'll see that it's going to print.
112
00:06:24,280 --> 00:06:25,960
True and False.
113
00:06:26,080 --> 00:06:26,570
OK.
114
00:06:26,620 --> 00:06:32,530
It's going return true or false because you know it is true it is false.
115
00:06:32,860 --> 00:06:33,250
Well
116
00:06:36,140 --> 00:06:40,450
you can also write it like this way.
117
00:06:40,820 --> 00:06:41,900
You can also write.
118
00:06:41,900 --> 00:06:44,940
This is I'm happy this way.
119
00:06:45,200 --> 00:06:46,010
OK.
120
00:06:46,040 --> 00:06:47,490
This is a closer block.
121
00:06:47,780 --> 00:06:51,600
The first parameter is it is an A you know creature.
122
00:06:51,650 --> 00:06:52,960
True it is.
123
00:06:53,070 --> 00:06:56,870
If the dollar sign first promise be it's not return false.
124
00:06:56,870 --> 00:07:00,400
So this thing has become this way.
125
00:07:00,510 --> 00:07:03,180
OK this is a very concise way of doing it.
126
00:07:03,350 --> 00:07:08,580
Well this is you can write Clojure blog link that is very rich simple nice and
simple.
127
00:07:08,900 --> 00:07:09,540
OK.
128
00:07:09,750 --> 00:07:16,880
Go anyway so we've designed is called Jablanica even a pass into this filter custom
filtering but we
129
00:07:16,880 --> 00:07:20,320
haven't designed a custom fields red you only designed is closure block.
130
00:07:20,330 --> 00:07:20,750
Right.
131
00:07:20,810 --> 00:07:26,410
Let's create custom filter create a function that takes the closure block.
132
00:07:26,780 --> 00:07:31,220
So this is what we do create a function.
133
00:07:31,220 --> 00:07:35,930
Simple call this simple string filter and then to enter grades.
134
00:07:35,960 --> 00:07:44,420
OK let's create entered grades let's quit grades and then let's call the operation.
135
00:07:44,570 --> 00:07:45,340
OK.
136
00:07:45,770 --> 00:07:51,200
And this thing takes string and the literature ball just like that.
137
00:07:51,860 --> 00:07:54,060
So the operation will be a closed block.
138
00:07:54,110 --> 00:07:57,300
So if you enter a it's something to return false true.
139
00:07:57,430 --> 00:07:59,580
If you enter B it's going to return false.
140
00:07:59,690 --> 00:08:02,680
Entered a Clojure Blondie's operation block here.
141
00:08:02,900 --> 00:08:15,140
OK but here let's call happy grade string value and then let's is value and the for
grade in grades
142
00:08:16,260 --> 00:08:17,140
reversed.
143
00:08:17,210 --> 00:08:19,210
Value going to enter.
144
00:08:19,440 --> 00:08:21,770
And then you execute this operation.
145
00:08:21,780 --> 00:08:26,980
So for example you get the strings filtering going to enter the grade.
146
00:08:27,090 --> 00:08:29,500
In the past was recent great.
147
00:08:29,900 --> 00:08:33,380
And then hearing that enter is mom happy.
148
00:08:33,530 --> 00:08:39,880
K. so we can use this operation right now.
149
00:08:39,880 --> 00:08:41,430
The operation is my happy tree.
150
00:08:41,470 --> 00:08:43,370
It's going to call is mom happy.
151
00:08:45,890 --> 00:08:55,650
If observation you enter grade you're happy great great plus great well explained
to you.
152
00:08:56,030 --> 00:08:57,420
See if I can explain this.
153
00:08:57,800 --> 00:09:02,560
So first born in this function you're going to enter a grade.
154
00:09:02,600 --> 00:09:08,780
So in this case you want to reduce and grade right here so we can teach the ABS
AKAs and and I believe
155
00:09:09,010 --> 00:09:10,320
and D right there.
156
00:09:10,840 --> 00:09:11,150
OK.
157
00:09:11,180 --> 00:09:14,220
And you're also going to enter operation which is a closer block.
158
00:09:14,660 --> 00:09:15,240
OK.
159
00:09:15,410 --> 00:09:17,310
So right now do you close your blog entry.
160
00:09:17,320 --> 00:09:23,480
Is mom happy but what do you what is my happy can do is when you enter when you
pass a it's going to
161
00:09:23,470 --> 00:09:26,900
turn true when you pass b it's going to turn false.
162
00:09:26,960 --> 00:09:27,790
Right.
163
00:09:28,370 --> 00:09:29,680
So you've answered it right there.
164
00:09:29,810 --> 00:09:34,690
So in the happy grade you have a string value array empty value.
165
00:09:34,700 --> 00:09:41,990
So for grade right now a Abebe or whatever and you can call this operation you
going to call this operation
166
00:09:42,230 --> 00:09:42,900
closure block.
167
00:09:42,920 --> 00:09:46,350
This is a cool algebra now operation is unhappy right.
168
00:09:46,390 --> 00:09:47,500
You enter the grade.
169
00:09:47,540 --> 00:09:54,690
So re-integrate can be a great can be B-GREEK and B D but if it returns true if
this block becomes true.
170
00:09:55,110 --> 00:10:01,910
And you can do a happy grape a panda agree upon the great if it falls OK if it
falls.
171
00:10:02,270 --> 00:10:05,270
You don't have to ride this way around this redundance.
172
00:10:05,270 --> 00:10:06,160
This is not good.
173
00:10:06,230 --> 00:10:11,690
It's just right there had the greatest falls you're going to simply ignore all of
this
174
00:10:15,170 --> 00:10:17,370
not the green one.
175
00:10:18,160 --> 00:10:20,070
Not the green one of the great one.
176
00:10:20,170 --> 00:10:21,090
OK.
177
00:10:21,650 --> 00:10:23,180
This is functional programming.
178
00:10:23,180 --> 00:10:30,070
What you did here you enter what you've entered is Operation blog into this Clojure
blog and that you're
179
00:10:30,070 --> 00:10:33,680
using Clojure block within this function using foreign look.
180
00:10:33,860 --> 00:10:37,850
OK so now what's happening is let's try.
181
00:10:37,850 --> 00:10:42,540
Print this print right there.
182
00:10:47,860 --> 00:10:49,000
Wise's zero.
183
00:10:49,200 --> 00:10:54,470
Well because you have none is because you have not returned dysfunction does not
return anything.
184
00:10:54,480 --> 00:10:56,940
So it looks to string.
185
00:10:57,330 --> 00:10:59,790
And then you can to return happy great
186
00:11:03,200 --> 00:11:04,990
right there.
187
00:11:11,440 --> 00:11:11,980
You'll see that.
188
00:11:12,020 --> 00:11:14,400
Ay ay ay ay.
189
00:11:14,590 --> 00:11:16,510
That's it that's what functional programming is.
190
00:11:16,510 --> 00:11:19,620
Functional Programming is nothing more than functions like this.
191
00:11:19,840 --> 00:11:25,990
And you can enter operation closure block and then run disclosure block within his
function and then
192
00:11:25,990 --> 00:11:28,070
do some operation to get the value you wanted.
193
00:11:28,150 --> 00:11:30,030
OK that's what functional programming is.
194
00:11:30,070 --> 00:11:37,060
So you'll see throughout this entire course and far less an entire chapter
documentor operation and
195
00:11:37,400 --> 00:11:40,940
what every operation entrain you will do that you will get the job done.
196
00:11:41,120 --> 00:11:41,860
OK.
197
00:11:42,220 --> 00:11:46,550
So this is one of the application I'm talking about.
198
00:11:47,410 --> 00:11:53,310
So right now given to close along indirectly you've indirectly passed.
199
00:11:53,380 --> 00:11:58,840
Is mom happy but you're also able to past Clojure blog directly again.
200
00:11:58,870 --> 00:11:59,660
How did you do it.
201
00:11:59,800 --> 00:12:08,110
Well I think you already knew how to do this you can do simple string filter
entered a grade recent
202
00:12:08,110 --> 00:12:11,500
grade and then here you can do something like this.
203
00:12:11,500 --> 00:12:13,940
This is what this is that you can use trailing.
204
00:12:14,480 --> 00:12:15,440
Arrogant.
205
00:12:16,060 --> 00:12:18,650
And then you can do let's call this.
206
00:12:18,860 --> 00:12:21,220
How are you doing right there.
207
00:12:21,310 --> 00:12:31,710
And then call it Elliman or you can Greg grade in return grade equals equals a or.
208
00:12:31,710 --> 00:12:32,350
This is
209
00:12:37,190 --> 00:12:40,120
right there blue print
210
00:12:42,960 --> 00:12:44,420
these are identical.
211
00:12:44,430 --> 00:12:49,760
Again if you're not familiar recloser and trying to take this lesson right now you
are doing this again.
212
00:12:49,770 --> 00:12:54,380
Please leave this lesson right now you got no closure 100 percent.
213
00:12:54,560 --> 00:12:56,320
There is no excuse for that.
214
00:12:56,340 --> 00:13:00,450
There's an entire chapter for you to learn in chapter three with closures.
215
00:13:00,450 --> 00:13:03,290
So make sure you understand what Clojure does.
216
00:13:03,310 --> 00:13:08,850
So this is the closure blog or ideas like a function and then this function will be
used by the simple
217
00:13:08,850 --> 00:13:13,550
string filter just like it above just like in a bar.
218
00:13:13,560 --> 00:13:14,890
This is a closure blog.
219
00:13:15,060 --> 00:13:15,850
OK.
220
00:13:16,170 --> 00:13:20,920
And then this Clojure blog is used by the filter internally.
221
00:13:21,020 --> 00:13:24,240
It is being executed internally by a filter function.
222
00:13:24,450 --> 00:13:30,790
Ok so you understand what the heck's going on with filter nothing more than running
this foreign LWB.
223
00:13:30,800 --> 00:13:34,120
And then if it's true then read appended is happy array.
224
00:13:34,520 --> 00:13:37,500
And that's what exactly happening this filter function as well.
225
00:13:37,730 --> 00:13:38,810
OK.
226
00:13:39,410 --> 00:13:42,560
So but this is not the best time.
227
00:13:42,580 --> 00:13:46,870
This not the best way to go Bill because this is not when it comes to function.
228
00:13:46,880 --> 00:13:50,080
We always want to make things generic right.
229
00:13:50,090 --> 00:13:50,690
We want to make things.
230
00:13:50,690 --> 00:13:56,610
Dinner is the one and only you only you don't want to only work with string value
that we've very that
231
00:13:56,610 --> 00:13:57,920
we've wasted your time.
232
00:13:57,920 --> 00:14:00,150
You want to make sure things work out with screen.
233
00:14:00,140 --> 00:14:03,010
It doesn't matter what you want to work with.
234
00:14:03,550 --> 00:14:06,380
So how to make things more how to make this function generic.
235
00:14:06,530 --> 00:14:08,830
Well you can do something like this.
236
00:14:08,940 --> 00:14:09,600
Let's roll.
237
00:14:09,790 --> 00:14:10,950
Filter.
238
00:14:11,210 --> 00:14:12,140
OK.
239
00:14:12,420 --> 00:14:14,260
Well let's call it but does it.
240
00:14:14,340 --> 00:14:20,440
You can use tiam to use t later but for now let's use to call it enter Ray Ray.
241
00:14:20,810 --> 00:14:25,810
Just like the above.
242
00:14:26,810 --> 00:14:31,810
And in fact actually know that the better way of doing it is just copy this.
243
00:14:32,430 --> 00:14:35,240
Just copy it is called a filter.
244
00:14:35,600 --> 00:14:38,600
And then let's call this array instead of grades.
245
00:14:38,600 --> 00:14:39,830
Call it Bob.
246
00:14:40,340 --> 00:14:45,860
And also you need to make sure to use and to identify itself as a generic function
you have to enter
247
00:14:45,860 --> 00:14:50,180
bubble here and that operation called it Bob.
248
00:14:50,250 --> 00:14:51,800
You know it returned Bob.
249
00:14:52,100 --> 00:14:52,820
OK.
250
00:14:53,240 --> 00:15:00,280
And then it's called This is called as a result because we don't know and this was
but a bunch of bulbs
251
00:15:00,300 --> 00:15:00,970
there.
252
00:15:01,190 --> 00:15:06,200
And it's called this element in sort of grades and they call this array.
253
00:15:06,240 --> 00:15:07,270
OK.
254
00:15:07,760 --> 00:15:22,370
And operators element and then you append the result append element and return
would return result.
255
00:15:24,260 --> 00:15:25,120
That's it.
256
00:15:25,610 --> 00:15:27,790
That's how you make a function generic too.
257
00:15:27,800 --> 00:15:33,080
Now you be able to as long as defined what bodies are as long as you find Bob you
can be screened can
258
00:15:33,080 --> 00:15:33,200
be.
259
00:15:33,200 --> 00:15:36,420
And now you're only able to enter all kinds of stuff.
260
00:15:36,530 --> 00:15:39,500
You can talk more and more practical application more and more.
261
00:15:39,650 --> 00:15:41,490
But for now is how you make a Jurich filter.
262
00:15:41,510 --> 00:15:43,100
And of course this is quite absurd.
263
00:15:43,100 --> 00:15:48,650
You don't make it you don't want to make things type Bubbe you want to make sure
that things like the
264
00:15:48,650 --> 00:15:50,320
better way will be using this team.
265
00:15:50,410 --> 00:15:56,480
My fields are T and to a rate operation T and then return t.
266
00:15:56,540 --> 00:15:57,240
OK.
267
00:15:57,590 --> 00:16:00,850
And everything else is the same as the above.
268
00:16:00,920 --> 00:16:07,220
I don't want to mention this right away because this thing can get pretty cold or
overwhelming.
269
00:16:07,850 --> 00:16:14,750
But as long as we understand the fundamentals how the filter function works behind
the scene this thing
270
00:16:14,750 --> 00:16:17,980
will just come across more familiar.
271
00:16:18,170 --> 00:16:24,290
OK so now we understand the fundamental Let's talk about the practical aspects how
we can use filter
272
00:16:24,290 --> 00:16:25,010
functions.
273
00:16:25,040 --> 00:16:26,180
OK.
274
00:16:26,420 --> 00:16:29,020
It took me a little while for me to get the very bottom.
275
00:16:29,300 --> 00:16:33,350
But it's important to get to know the fundamentals how the filter function works.
276
00:16:33,350 --> 00:16:39,890
It's impossible to know every common functions filter math redos there are a lot
more than just filtered
277
00:16:39,890 --> 00:16:42,100
out probably hundreds of functions.
278
00:16:42,200 --> 00:16:47,510
But as long as don't get to the fundamentals that you're using Clojure blog and
that Clojure blog is
279
00:16:47,510 --> 00:16:52,580
used within the function then and then you want to make things generic as long as
you understand the
280
00:16:52,580 --> 00:16:55,850
fundamentals everything else become much easier.
281
00:16:55,850 --> 00:17:01,420
So now let's get to the fundamentally practical examples with the developer.
282
00:17:01,550 --> 00:17:10,100
OK so now you want to let's see if a student from one 200 list you want to get the
student from only
283
00:17:10,100 --> 00:17:18,510
to who or who who who succeeded in getting grade of 93 or above.
284
00:17:18,620 --> 00:17:20,560
OK because that's me.
285
00:17:20,930 --> 00:17:24,970
So let's say let student A-students let's call them.
286
00:17:25,040 --> 00:17:29,800
I'm going to use my filter right above your entire array value.
287
00:17:30,020 --> 00:17:35,080
Let's call an array and one to 100.
288
00:17:35,210 --> 00:17:41,660
Again make sure you define what t is you're able to define what t is because right
now one two hundred
289
00:17:41,660 --> 00:17:46,110
is able to sell teated till we have the hey right now I'm working with it.
290
00:17:46,160 --> 00:17:46,600
OK.
291
00:17:46,760 --> 00:17:51,990
But in this operation here going to end through Clojure block OK right here.
292
00:17:52,280 --> 00:17:53,870
And you have to do you have to.
293
00:17:53,870 --> 00:17:55,520
You can do this.
294
00:17:56,030 --> 00:18:01,900
The first parameter dollar sign 0 is greater than 93
295
00:18:04,190 --> 00:18:11,040
93 and or an we call it was.
296
00:18:11,050 --> 00:18:12,050
And I can see
297
00:18:14,830 --> 00:18:21,740
and zero is smaller and then hundred equals 200.
298
00:18:23,590 --> 00:18:35,920
So now print a student right there it will only get the value who are graded in 93
and also smaller
299
00:18:35,920 --> 00:18:39,150
than a greater than equal less than 100.
300
00:18:39,220 --> 00:18:39,860
OK.
301
00:18:40,060 --> 00:18:41,700
So that's how you filter stuff out.
302
00:18:43,430 --> 00:18:44,600
That's it.
303
00:18:44,810 --> 00:18:48,080
That's what filter can be used when you're working with a database.
304
00:18:48,160 --> 00:18:53,130
So you want to get a value from a database and you do want to filter out some sort
of a data.
305
00:18:53,300 --> 00:18:58,620
You want to have someone like you know a user name has because Bob user name ASC-P
Colesville bubbly
306
00:18:58,640 --> 00:19:03,590
past protec will say that you can use simply filter function without having to use
this for and live
307
00:19:04,130 --> 00:19:05,170
all the time.
308
00:19:05,480 --> 00:19:06,550
This is quite heated.
309
00:19:06,560 --> 00:19:07,330
You don't want to do that.
310
00:19:07,460 --> 00:19:09,790
You only simply functions OK.
311
00:19:10,370 --> 00:19:17,720
And then you can customize the function by just entering the closed block that you
work with can customize
312
00:19:17,720 --> 00:19:20,110
a clover block game.
313
00:19:20,270 --> 00:19:22,070
This port can be a little confusing.
314
00:19:22,190 --> 00:19:28,910
But again we all cover many times how to work with Clojure if you're not
comfortable just make sure
315
00:19:28,910 --> 00:19:32,470
we viewed a closure blog and try to review as much as you can.
316
00:19:32,470 --> 00:19:34,630
Good thing I made myself clear.
317
00:19:35,090 --> 00:19:40,550
So now we talked about how to filter numbers it can filter all kinds of stuff but
you can also filter
318
00:19:40,550 --> 00:19:43,010
out vote counting.
319
00:19:43,010 --> 00:19:44,490
So Lessie of votes.
320
00:19:44,810 --> 00:19:45,880
True False True or false.
321
00:19:45,980 --> 00:19:48,870
If you want to get the value which is true how did you de.
322
00:19:49,130 --> 00:19:58,400
Well if you want to get the valent to value you can say true answer equals my
filter array to enter
323
00:19:58,400 --> 00:19:59,480
the array value.
324
00:19:59,490 --> 00:20:08,120
And this operation is going to use this what you call the enter closure box and the
has to be true.
325
00:20:14,970 --> 00:20:16,490
Let's see a look at it now.
326
00:20:16,520 --> 00:20:20,630
Print true answer true answer
327
00:20:26,180 --> 00:20:29,010
Come on True and true.
328
00:20:29,280 --> 00:20:29,710
OK.
329
00:20:29,730 --> 00:20:32,830
So you only gain the true value from this answer array.
330
00:20:33,210 --> 00:20:33,770
OK.
331
00:20:35,360 --> 00:20:43,980
It my making sense hopefully I'm making sense hopefully if I'm not making sense
well by the way I've
332
00:20:43,980 --> 00:20:49,320
written into an article for you guys to just review this article if you're not
confused how are we going
333
00:20:49,320 --> 00:20:52,330
to use the exact same principles and ideas here.
334
00:20:52,560 --> 00:20:59,010
So you know you're using grade grade so if you are so confused Take a look at his
article in the speech.
335
00:20:59,400 --> 00:21:00,730
That's what I can do for you.
336
00:21:00,730 --> 00:21:02,430
Or you can always ask me a question to 101.
337
00:21:02,440 --> 00:21:04,530
I will always answer for you.
338
00:21:04,950 --> 00:21:13,110
So you can also use trailing closer method my filter array and then the first
member of equals equals
339
00:21:13,110 --> 00:21:13,790
false.
340
00:21:14,130 --> 00:21:15,460
You get the false answer.
341
00:21:15,770 --> 00:21:16,310
OK.
342
00:21:18,310 --> 00:21:22,270
But however what's the good thing about filtering is swithe.
343
00:21:22,270 --> 00:21:25,630
Foundation library comes with its own filter.
344
00:21:25,630 --> 00:21:34,810
For example you can use something like this array is a hunt one two hundred is
actually comes along
345
00:21:34,810 --> 00:21:36,500
with a built in filter method.
346
00:21:36,550 --> 00:21:39,620
This filter method is already designed by Apple engineers.
347
00:21:39,880 --> 00:21:43,310
And then you do filter and then filter again.
348
00:21:43,440 --> 00:21:44,100
All right.
349
00:21:44,380 --> 00:21:52,300
This thing returns of the returns a string value of End of story end of an array
and then you can filter
350
00:21:52,300 --> 00:21:56,360
again to get the value of int and array.
351
00:21:56,470 --> 00:21:58,410
OK you can call it chaining.
352
00:21:58,450 --> 00:21:59,530
We did this once.
353
00:21:59,590 --> 00:22:03,740
Second time do this third time to be called chaining happens continuously.
354
00:22:03,850 --> 00:22:09,070
You can do to it when it comes to reactive programming and ease a lot of chaining I
do planning the
355
00:22:09,070 --> 00:22:14,830
future recover and relapse swift reality programming which I love you'll never code
the same way.
356
00:22:14,830 --> 00:22:21,190
It's a it's basically learning how to code how to create UI with your using full
function programming
357
00:22:21,580 --> 00:22:23,760
so much faster so much more readable.
358
00:22:24,070 --> 00:22:26,740
But just that's what change does.
359
00:22:27,210 --> 00:22:32,720
OK so how to have a filter function like this.
360
00:22:33,010 --> 00:22:37,980
Well this is the most pure form you can ever have.
361
00:22:38,330 --> 00:22:44,870
So right now extension we have extension to array so this desert's 100 and Raintree
array you have enter
362
00:22:44,930 --> 00:22:45,870
my filter.
363
00:22:45,980 --> 00:22:46,550
OK.
364
00:22:46,940 --> 00:22:49,760
And then there is an operation right here.
365
00:22:49,820 --> 00:22:54,730
Element Element Bifrost the type of this array.
366
00:22:54,970 --> 00:22:57,220
It has to be the associate type protocol in programming.
367
00:22:57,220 --> 00:23:03,350
I'm not going Octobre cover about a couple Ghobadi right now but element refers to
the type of the type
368
00:23:03,350 --> 00:23:05,130
of the array.
369
00:23:05,360 --> 00:23:12,360
Right now the array is but the type of the element is what bits are mine based on
devout value can't
370
00:23:12,360 --> 00:23:15,180
really work with and then returns.
371
00:23:15,530 --> 00:23:16,310
The rest is the same.
372
00:23:16,310 --> 00:23:20,400
Self refers to the object itself and then appended append.
373
00:23:20,420 --> 00:23:25,690
So now you're able to use something like this.
374
00:23:25,780 --> 00:23:29,070
This is and this is a minefield through coming from this one.
375
00:23:29,230 --> 00:23:30,560
OK.
376
00:23:30,700 --> 00:23:35,800
You're able to do the well and this lesson talked about the principle behind
functional programming
377
00:23:36,100 --> 00:23:37,660
when it comes using filter.
378
00:23:37,660 --> 00:23:44,770
It was a pretty long lesson but all I want to see is is nothing more than passing
closure blog and then
379
00:23:44,800 --> 00:23:48,310
pleasure blog is using use within dysfunction within.
380
00:23:48,370 --> 00:23:51,080
Just like your operation right there.
381
00:23:51,100 --> 00:23:53,540
OK that's what Fomitch reprogram Yes.
382
00:23:53,680 --> 00:24:00,220
And depending on what you enter within the Clojure to it just manipulate the data
so you can do all
383
00:24:00,220 --> 00:24:02,320
kinds of stuff with one line of code.
384
00:24:03,040 --> 00:24:07,570
And this Mileson might be a little tough for you and also it's tough for me to
explain a thing or sort
385
00:24:07,570 --> 00:24:13,380
of Sodor lot throughout the entire lesson but hopefully a mate might have made
sense if not if you're
386
00:24:13,390 --> 00:24:17,320
still struggling a little bit you can always ask me questions I'll be right there
for you guys.
387
00:24:17,510 --> 00:24:23,050
And if you need my help just call me up through the phone or e-mails let you know
what to do to see
388
00:24:23,050 --> 00:24:23,790
you guys in person.
389
00:24:23,800 --> 00:24:30,250
I'm sorry I mean you feel like it didn't it wasn't the best lesson that I could
present myself with
390
00:24:30,670 --> 00:24:34,950
but hopefully you guys understood.
391
00:24:35,320 --> 00:24:37,490
So see you guys in the next lesson from gastrulation.
392
00:24:37,510 --> 00:24:40,800
Lauren what goes under the hood of filters.
393
00:24:40,810 --> 00:24:42,700
One of the most popular functions out there.
394
00:24:42,730 --> 00:24:48,260
You discovered that in sweet functional programming a closure block is added at the
end of a function
395
00:24:48,310 --> 00:24:54,280
and that closure blog is use within that function internally This principle applies
to every other major
396
00:24:54,280 --> 00:24:55,730
function that we take a look at today.
397
00:24:55,750 --> 00:24:58,110
That is the basis of functional programming.
398
00:24:58,150 --> 00:25:03,010
And we're going to take a look at how all their functions uses the same approach as
well along with
399
00:25:03,190 --> 00:25:09,670
generics swift function programming provides reusability as well as skill ability
in your codebase.
400
00:25:09,700 --> 00:25:15,910
At the end of this lesing talked about aliment which refers to a type of the array
in chapter 10 you
401
00:25:15,910 --> 00:25:21,040
will discover what the Alamo refers to when talking about code in programming and
swift.
402
00:25:21,220 --> 00:25:22,990
So see you in the next lesson.