WEBVTT

1
00:00:11.395 --> 00:00:11.685
Yeah.

2
00:00:11.815 --> 00:00:14.165
<00:00:11.815>Hello. <00:00:12.281>So <00:00:12.748>functional <00:00:13.215>programming.

3
00:00:16.585 --> 00:00:17.605
<00:00:16.585>Who <00:00:16.891>here <00:00:17.197>is <00:00:17.503>here?

4
00:00:17.605 --> 00:00:19.445
<00:00:17.605>Because <00:00:17.745>you <00:00:17.885>know <00:00:18.025>c <00:00:18.165>plus <00:00:18.305>plus <00:00:18.445>the <00:00:18.585>know <00:00:18.725>C <00:00:18.865>plus <00:00:19.005>bus.

5
00:00:20.715 --> 00:00:23.325
<00:00:20.715>Okay, <00:00:20.948>excellent. <00:00:21.181>Doing <00:00:21.415>also <00:00:21.648>no <00:00:21.881>functional <00:00:22.115>programming.

6
00:00:24.195 --> 00:00:28.405
<00:00:24.195>Okay, <00:00:24.370>fewer <00:00:24.545>people. <00:00:24.720>So <00:00:24.895>functional <00:00:25.070>programming <00:00:25.245>is <00:00:25.420>a <00:00:25.595>form

7
00:00:28.405 --> 00:00:29.605
<00:00:28.405>of <00:00:28.945>declarative <00:00:29.485>programming.

8
00:00:29.745 --> 00:00:32.645
<00:00:29.745>So <00:00:29.945>in <00:00:30.145>declarative <00:00:30.345>programming <00:00:30.545>you <00:00:30.745>specify <00:00:30.945>desired <00:00:31.145>outcomes

9
00:00:32.705 --> 00:00:34.685
<00:00:32.705>and <00:00:32.985>not <00:00:33.265>the <00:00:33.545>individual <00:00:33.824>instructions <00:00:34.105>necessary

10
00:00:34.685 --> 00:00:35.725
<00:00:34.685>to <00:00:34.997>achieve <00:00:35.309>this <00:00:35.621>outcome.

11
00:00:35.985 --> 00:00:38.605
<00:00:35.985>And <00:00:36.185>in <00:00:36.385>functional <00:00:36.585>programming <00:00:36.785>specifically, <00:00:36.985>you <00:00:37.185>do <00:00:37.385>it

12
00:00:38.605 --> 00:00:41.645
<00:00:38.605>by <00:00:38.805>composing <00:00:39.004>functions <00:00:39.205>which <00:00:39.404>are <00:00:39.605>pure <00:00:39.805>mathematical <00:00:40.004>mappings

13
00:00:41.645 --> 00:00:42.765
<00:00:41.645>from <00:00:41.981>inputs <00:00:42.317>to <00:00:42.653>outputs.

14
00:00:43.905 --> 00:00:45.725
<00:00:43.905>For <00:00:44.105>example, <00:00:44.305>here's <00:00:44.505>a <00:00:44.705>bit <00:00:44.905>of <00:00:45.105>hascal <00:00:45.305>count,

15
00:00:45.875 --> 00:00:48.125
<00:00:45.875>it's <00:00:46.075>a <00:00:46.275>classical <00:00:46.475>definition <00:00:46.675>of <00:00:46.875>the <00:00:47.075>faculty <00:00:47.275>function.

16
00:00:48.185 --> 00:00:50.085
<00:00:48.185>It <00:00:48.360>takes <00:00:48.535>an <00:00:48.710>inter <00:00:48.885>and <00:00:49.060>it <00:00:49.235>returns <00:00:49.410>an <00:00:49.585>integer.

17
00:00:50.185 --> 00:00:52.005
<00:00:50.185>And <00:00:50.418>then <00:00:50.651>we <00:00:50.885>just <00:00:51.118>specify <00:00:51.351>the <00:00:51.585>outcome.

18
00:00:52.145 --> 00:00:54.125
<00:00:52.145>We <00:00:52.378>say <00:00:52.611>the <00:00:52.845>faculty <00:00:53.078>of <00:00:53.311>zeros <00:00:53.545>one

19
00:00:54.265 --> 00:00:55.965
<00:00:54.265>and <00:00:54.498>the <00:00:54.731>faculty <00:00:54.965>of <00:00:55.198>N <00:00:55.431>is <00:00:55.665>equal

20
00:00:55.965 --> 00:00:57.765
<00:00:55.965>to <00:00:56.165>N <00:00:56.365>times <00:00:56.565>faculty <00:00:56.765>of <00:00:56.965>N <00:00:57.165>minus <00:00:57.365>one.

21
00:00:58.035 --> 00:00:59.245
<00:00:58.035>This <00:00:58.397>is <00:00:58.760>purely <00:00:59.123>declared,

22
00:00:59.385 --> 00:01:01.165
<00:00:59.385>we <00:00:59.665>don't <00:00:59.945>specify <00:01:00.224>any <00:01:00.504>instructions <00:01:00.785>there.

23
00:01:01.165 --> 00:01:03.125
<00:01:01.165>We <00:01:01.339>just <00:01:01.515>say <00:01:01.690>the <00:01:01.865>rules <00:01:02.040>to <00:01:02.214>compute <00:01:02.390>the <00:01:02.565>faculty.

24
00:01:04.715 --> 00:01:07.245
<00:01:04.715>This <00:01:04.870>is <00:01:05.026>more <00:01:05.181>clear <00:01:05.337>in <00:01:05.492>the <00:01:05.648>sort <00:01:05.803>of <00:01:05.959>classical <00:01:06.115>soil,

25
00:01:07.535 --> 00:01:08.685
<00:01:07.535>quick <00:01:07.880>sort <00:01:08.225>in <00:01:08.570>Haskell.

26
00:01:08.905 --> 00:01:10.885
<00:01:08.905>So <00:01:09.060>it's <00:01:09.216>a <00:01:09.371>function <00:01:09.527>that <00:01:09.682>takes <00:01:09.838>a <00:01:09.993>list <00:01:10.149>of <00:01:10.305>integer

27
00:01:10.885 --> 00:01:12.085
<00:01:10.885>and <00:01:11.155>we <00:01:11.425>took <00:01:11.695>of <00:01:11.965>integer

28
00:01:12.505 --> 00:01:15.525
<00:01:12.505>and <00:01:12.612>we <00:01:12.720>say <00:01:12.828>that <00:01:12.935>the <00:01:13.043>sort <00:01:13.151>of <00:01:13.258>the <00:01:13.366>empty <00:01:13.474>list <00:01:13.581>is <00:01:13.689>the <00:01:13.797>empty <00:01:13.905>list

29
00:01:15.665 --> 00:01:18.045
<00:01:15.664>and <00:01:15.820>the <00:01:15.976>sort <00:01:16.131>of <00:01:16.287>a <00:01:16.442>list <00:01:16.598>containing <00:01:16.753>one <00:01:16.909>element <00:01:17.065>followed

30
00:01:18.045 --> 00:01:19.685
<00:01:18.045>by <00:01:18.325>some <00:01:18.605>more <00:01:18.885>elements <00:01:19.165>is <00:01:19.445>given

31
00:01:19.745 --> 00:01:21.805
<00:01:19.745>by <00:01:19.945>taking <00:01:20.145>all <00:01:20.345>elements <00:01:20.545>less <00:01:20.745>than <00:01:20.945>that <00:01:21.145>element.

32
00:01:22.035 --> 00:01:24.765
<00:01:22.035>That <00:01:22.210>element <00:01:22.384>and <00:01:22.560>all <00:01:22.735>elements, <00:01:22.910>uh, <00:01:23.085>greater <00:01:23.259>than <00:01:23.435>that.

33
00:01:24.985 --> 00:01:27.725
<00:01:24.985>And <00:01:25.125>then <00:01:25.265>our <00:01:25.405>list <00:01:25.545>is <00:01:25.685>sorted. <00:01:25.825>Those <00:01:25.965>are <00:01:26.105>the <00:01:26.245>two <00:01:26.385>rules.

34
00:01:29.065 --> 00:01:30.925
<00:01:29.065>Now <00:01:29.265>why <00:01:29.465>do <00:01:29.664>you <00:01:29.865>wanna <00:01:30.065>use <00:01:30.265>functional <00:01:30.465>programming?

35
00:01:32.245 --> 00:01:33.925
<00:01:32.245>Functional <00:01:32.711>programming <00:01:33.178>eliminates <00:01:33.645>state

36
00:01:34.305 --> 00:01:35.445
<00:01:34.305>and <00:01:34.561>that's <00:01:34.818>really <00:01:35.074>nice <00:01:35.330>because

37
00:01:35.445 --> 00:01:36.525
<00:01:35.445>that's <00:01:35.639>where <00:01:35.833>all <00:01:36.028>the <00:01:36.222>bugs <00:01:36.417>are.

38
00:01:36.545 --> 00:01:38.245
<00:01:36.545>If <00:01:36.700>you <00:01:36.856>don't <00:01:37.011>have <00:01:37.167>states, <00:01:37.322>you <00:01:37.478>don't <00:01:37.633>have <00:01:37.789>bug <00:01:37.945>due

39
00:01:38.245 --> 00:01:39.965
<00:01:38.245>to <00:01:38.525>invalid <00:01:38.805>states <00:01:39.085>broken <00:01:39.365>in <00:01:39.645>variance,

40
00:01:40.105 --> 00:01:42.805
<00:01:40.104>you <00:01:40.279>don't <00:01:40.454>have <00:01:40.630>complex <00:01:40.804>object <00:01:40.979>references <00:01:41.154>in <00:01:41.329>a <00:01:41.505>shared

41
00:01:42.805 --> 00:01:43.885
<00:01:42.805>object <00:01:43.129>graph <00:01:43.453>or <00:01:43.776>something.

42
00:01:44.225 --> 00:01:45.565
<00:01:44.225>You <00:01:44.466>don't <00:01:44.707>have <00:01:44.948>any <00:01:45.189>waste <00:01:45.431>conditions

43
00:01:45.565 --> 00:01:46.805
<00:01:45.565>because <00:01:45.751>you <00:01:45.937>don't <00:01:46.123>have <00:01:46.309>any <00:01:46.495>shared <00:01:46.681>state.

44
00:01:46.945 --> 00:01:49.085
<00:01:46.945>Uh, <00:01:47.100>and <00:01:47.256>it's <00:01:47.411>also <00:01:47.567>trivial <00:01:47.722>to <00:01:47.878>paralyze <00:01:48.033>as <00:01:48.189>we'll <00:01:48.345>see.

45
00:01:50.265 --> 00:01:51.885
<00:01:50.265>So <00:01:50.545>functioning <00:01:50.825>programming <00:01:51.105>is <00:01:51.385>a <00:01:51.665>weight.

46
00:01:52.025 --> 00:01:53.645
<00:01:52.025>Why <00:01:52.225>do <00:01:52.425>you <00:01:52.625>all <00:01:52.825>use <00:01:53.025>c <00:01:53.225>plus <00:01:53.425>plus?

47
00:01:53.645 --> 00:01:55.165
<00:01:53.645>Why <00:01:53.873>don't <00:01:54.101>you <00:01:54.329>write <00:01:54.557>haskel <00:01:54.785>or <00:01:55.012>something?

48
00:01:55.515 --> 00:01:58.325
<00:01:55.515>Well, <00:01:55.748>it's <00:01:55.981>because <00:01:56.215>fundamentally <00:01:56.448>functional <00:01:56.681>programming <00:01:56.915>does

49
00:01:58.325 --> 00:01:59.525
<00:01:58.325>not <00:01:58.595>map <00:01:58.865>neatly <00:01:59.135>to <00:01:59.405>hardware

50
00:01:59.525 --> 00:02:01.285
<00:01:59.525>because <00:01:59.875>hardware <00:02:00.225>is <00:02:00.575>imperative, <00:02:00.925>right?

51
00:02:01.515 --> 00:02:03.085
<00:02:01.515>This <00:02:01.795>makes <00:02:02.075>it <00:02:02.355>harder <00:02:02.635>to <00:02:02.915>optimize.

52
00:02:03.085 --> 00:02:05.005
<00:02:03.085>You <00:02:03.240>have <00:02:03.396>to <00:02:03.551>like <00:02:03.707>find <00:02:03.862>some <00:02:04.018>way <00:02:04.173>to <00:02:04.329>map <00:02:04.485>it

53
00:02:05.005 --> 00:02:06.165
<00:02:05.005>to <00:02:05.353>sequences <00:02:05.701>of <00:02:06.049>instructions.

54
00:02:06.315 --> 00:02:09.445
<00:02:06.315>It's <00:02:06.470>harder <00:02:06.626>to <00:02:06.781>use <00:02:06.937>native <00:02:07.092>tools <00:02:07.248>like <00:02:07.403>debuggers <00:02:07.559>or <00:02:07.715>profiles

55
00:02:09.705 --> 00:02:12.725
<00:02:09.705>and <00:02:09.880>it's <00:02:10.055>like <00:02:10.230>harder <00:02:10.405>to <00:02:10.580>interact <00:02:10.755>with <00:02:10.930>libraries <00:02:11.105>directly.

56
00:02:12.785 --> 00:02:17.685
<00:02:12.785>Um, <00:02:12.901>low <00:02:13.018>level <00:02:13.135>at <00:02:13.251>the <00:02:13.368>os, <00:02:13.484>however, <00:02:13.601>we <00:02:13.718>are <00:02:13.835>doing <00:02:13.951>c <00:02:14.068>plus <00:02:14.185>plus.

57
00:02:18.145 --> 00:02:20.205
<00:02:18.145>And <00:02:18.320>C <00:02:18.495>plus <00:02:18.670>plus <00:02:18.845>isn't <00:02:19.020>a <00:02:19.195>pure <00:02:19.370>functional <00:02:19.545>language.

58
00:02:20.395 --> 00:02:21.405
<00:02:20.395>That <00:02:20.622>means <00:02:20.849>we <00:02:21.076>don't <00:02:21.304>need

59
00:02:21.405 --> 00:02:23.845
<00:02:21.405>to <00:02:21.685>use <00:02:21.965>functional <00:02:22.245>programming <00:02:22.525>paradigms, <00:02:22.805>right?

60
00:02:24.265 --> 00:02:25.725
<00:02:24.265>We <00:02:24.452>don't <00:02:24.640>need <00:02:24.828>to <00:02:25.015>use <00:02:25.203>them <00:02:25.391>for <00:02:25.579>everything.

61
00:02:25.725 --> 00:02:27.405
<00:02:25.725>We <00:02:25.900>can <00:02:26.075>only <00:02:26.250>use <00:02:26.424>them <00:02:26.600>when <00:02:26.775>it <00:02:26.950>makes <00:02:27.125>sense.

62
00:02:29.065 --> 00:02:30.205
<00:02:29.065>And <00:02:29.578>functional <00:02:30.090>programming

63
00:02:30.205 --> 00:02:31.725
<00:02:30.204>fundamentally <00:02:30.547>is <00:02:30.888>all <00:02:31.231>about <00:02:31.572>composition.

64
00:02:32.145 --> 00:02:35.005
<00:02:32.145>So <00:02:32.285>we <00:02:32.425>can <00:02:32.565>leverage <00:02:32.705>that. <00:02:32.845>We <00:02:32.985>can <00:02:33.125>write <00:02:33.265>small <00:02:33.405>building <00:02:33.545>blocks

65
00:02:35.005 --> 00:02:37.765
<00:02:35.005>using <00:02:35.204>efficient, <00:02:35.405>optimized, <00:02:35.605>and <00:02:35.805>well <00:02:36.005>tested <00:02:36.204>C <00:02:36.405>passcode

66
00:02:37.945 --> 00:02:40.645
<00:02:37.945>and <00:02:38.120>then <00:02:38.295>we <00:02:38.470>can <00:02:38.644>compose <00:02:38.820>them <00:02:38.995>using <00:02:39.170>functional <00:02:39.345>paradigms

67
00:02:40.745 --> 00:02:42.805
<00:02:40.745>and <00:02:40.900>that <00:02:41.056>we <00:02:41.211>will <00:02:41.367>have <00:02:41.522>the <00:02:41.678>best <00:02:41.833>of <00:02:41.989>both <00:02:42.145>worlds.

68
00:02:43.585 --> 00:02:44.645
<00:02:43.585>And <00:02:43.823>in <00:02:44.062>the <00:02:44.300>stock, <00:02:44.539>uh,

69
00:02:44.705 --> 00:02:46.445
<00:02:44.704>we <00:02:44.904>will <00:02:45.105>look <00:02:45.304>at <00:02:45.505>three <00:02:45.704>kinds <00:02:45.904>of <00:02:46.105>composing.

70
00:02:47.925 --> 00:02:50.305
<00:02:47.925>We <00:02:48.125>will <00:02:48.325>begin <00:02:48.525>by <00:02:48.725>looking <00:02:48.925>at <00:02:49.125>composing <00:02:49.325>algorithms.

71
00:02:50.685 --> 00:02:52.425
<00:02:50.685>And <00:02:50.965>this <00:02:51.245>is <00:02:51.525>really <00:02:51.805>the <00:02:52.085>meat.

72
00:02:52.975 --> 00:02:55.025
<00:02:52.975>This <00:02:53.150>is <00:02:53.325>where <00:02:53.500>function <00:02:53.674>programming <00:02:53.850>really <00:02:54.025>shines <00:02:54.200>in <00:02:54.375>cpa.

73
00:02:55.605 --> 00:02:57.745
<00:02:55.605>And <00:02:55.760>this <00:02:55.916>is <00:02:56.071>also <00:02:56.227>where <00:02:56.382>I'm <00:02:56.538>most <00:02:56.693>passionate <00:02:56.849>about <00:02:57.005>it.

74
00:02:59.135 --> 00:03:00.755
<00:02:59.135>So <00:02:59.310>I've <00:02:59.484>bought <00:02:59.660>a <00:02:59.834>couple <00:03:00.010>of <00:03:00.185>lead <00:03:00.359>code <00:03:00.535>problems

75
00:03:00.755 --> 00:03:01.915
<00:03:00.755>and <00:03:00.929>we're <00:03:01.103>gonna <00:03:01.277>solve <00:03:01.451>them <00:03:01.625>in <00:03:01.798>a

76
00:03:02.115 --> 00:03:03.155
<00:03:02.115>functional <00:03:02.302>style <00:03:02.489>in <00:03:02.676>c <00:03:02.863>plus <00:03:03.051>plus.

77
00:03:04.525 --> 00:03:06.785
<00:03:04.525>The <00:03:04.700>first <00:03:04.875>problem <00:03:05.050>is <00:03:05.225>a <00:03:05.400>very <00:03:05.575>simple <00:03:05.750>one, <00:03:05.925>right?

78
00:03:06.845 --> 00:03:08.945
<00:03:06.845>We <00:03:07.020>are <00:03:07.195>given <00:03:07.370>a <00:03:07.545>list <00:03:07.720>of <00:03:07.895>non <00:03:08.070>empty <00:03:08.245>integer

79
00:03:09.365 --> 00:03:11.625
<00:03:09.365>and <00:03:09.598>we <00:03:09.831>wanna <00:03:10.065>find <00:03:10.298>the <00:03:10.531>biggest <00:03:10.765>magnitude

80
00:03:11.625 --> 00:03:12.905
<00:03:11.625>of <00:03:11.817>an <00:03:12.009>odd <00:03:12.201>integer <00:03:12.393>in <00:03:12.585>the <00:03:12.777>list.

81
00:03:14.125 --> 00:03:16.225
<00:03:14.125>So <00:03:14.300>if <00:03:14.475>this <00:03:14.650>is <00:03:14.825>our <00:03:15.000>list <00:03:15.175>of <00:03:15.350>integer, <00:03:15.525>um,

82
00:03:16.475 --> 00:03:18.945
<00:03:16.475>seven <00:03:16.650>is <00:03:16.825>the <00:03:17.000>biggest <00:03:17.174>odd <00:03:17.350>magnitude <00:03:17.525>in <00:03:17.700>that <00:03:17.875>list.

83
00:03:19.045 --> 00:03:21.665
<00:03:19.045>So <00:03:19.185>the <00:03:19.325>magnitude <00:03:19.465>is <00:03:19.605>just <00:03:19.745>the <00:03:19.885>um, <00:03:20.025>take <00:03:20.165>the <00:03:20.305>absolute <00:03:20.445>value

84
00:03:21.665 --> 00:03:23.825
<00:03:21.665>and <00:03:21.840>then <00:03:22.015>we <00:03:22.190>only <00:03:22.364>take <00:03:22.540>the <00:03:22.715>um, <00:03:22.890>odd <00:03:23.065>ones.

85
00:03:25.645 --> 00:03:26.985
<00:03:25.645>And <00:03:25.886>this <00:03:26.127>is <00:03:26.368>the <00:03:26.609>trivial <00:03:26.851>code.

86
00:03:26.985 --> 00:03:28.705
<00:03:26.985>You <00:03:27.140>can <00:03:27.296>write <00:03:27.451>using <00:03:27.607>an <00:03:27.762>IM <00:03:27.918>period <00:03:28.073>of <00:03:28.229>style, <00:03:28.385>right?

87
00:03:28.705 --> 00:03:29.705
<00:03:28.704>These <00:03:29.005>are <00:03:29.304>the <00:03:29.605>instructions

88
00:03:29.705 --> 00:03:30.865
<00:03:29.704>that <00:03:29.879>you <00:03:30.053>need <00:03:30.227>to <00:03:30.401>solve <00:03:30.575>this <00:03:30.749>problem.

89
00:03:31.285 --> 00:03:32.865
<00:03:31.285>We <00:03:31.518>get <00:03:31.751>our <00:03:31.984>range <00:03:32.218>of <00:03:32.451>uh, <00:03:32.685>elements.

90
00:03:32.885 --> 00:03:35.105
<00:03:32.885>We <00:03:33.084>remember <00:03:33.285>current <00:03:33.484>candidate, <00:03:33.685>we <00:03:33.885>loop <00:03:34.084>over <00:03:34.285>them.

91
00:03:35.325 --> 00:03:38.745
<00:03:35.325>We <00:03:35.464>only <00:03:35.605>consider <00:03:35.744>the <00:03:35.885>magnitude, <00:03:36.024>we <00:03:36.165>filter <00:03:36.304>out <00:03:36.445>the <00:03:36.584>odd <00:03:36.725>ones.

92
00:03:38.925 --> 00:03:40.345
<00:03:38.925>Um, <00:03:39.138>and <00:03:39.351>then <00:03:39.564>we <00:03:39.777>update <00:03:39.990>it, <00:03:40.203>right?

93
00:03:40.375 --> 00:03:42.225
<00:03:40.375>This <00:03:40.725>is <00:03:41.075>straightforward <00:03:41.425>imperative <00:03:41.775>code.

94
00:03:42.805 --> 00:03:44.505
<00:03:42.805>So <00:03:42.960>how <00:03:43.116>would <00:03:43.271>we <00:03:43.427>do <00:03:43.582>it <00:03:43.738>in <00:03:43.893>a <00:03:44.049>functional <00:03:44.205>way?

95
00:03:44.805 --> 00:03:47.105
<00:03:44.805>And <00:03:44.932>the <00:03:45.059>question <00:03:45.186>you <00:03:45.314>always <00:03:45.441>need <00:03:45.568>to <00:03:45.695>ask <00:03:45.823>yourself <00:03:45.950>for <00:03:46.077>that <00:03:46.205>is

96
00:03:47.135 --> 00:03:48.585
<00:03:47.135>what <00:03:47.461>is <00:03:47.787>the <00:03:48.113>fundamental <00:03:48.440>composition?

97
00:03:49.245 --> 00:03:50.745
<00:03:49.245>And <00:03:49.515>here <00:03:49.785>we <00:03:50.055>have <00:03:50.325>three <00:03:50.595>sub-problems.

98
00:03:51.045 --> 00:03:53.105
<00:03:51.045>The <00:03:51.278>first <00:03:51.511>sub-problem <00:03:51.745>is <00:03:51.978>we <00:03:52.211>wanna <00:03:52.445>compute

99
00:03:53.105 --> 00:03:54.185
<00:03:53.105>the <00:03:53.347>magnitude <00:03:53.591>of <00:03:53.834>each <00:03:54.077>number.

100
00:03:54.845 --> 00:03:57.305
<00:03:54.845>The <00:03:54.984>second <00:03:55.125>sub <00:03:55.265>problem <00:03:55.405>is <00:03:55.545>we <00:03:55.685>wanna <00:03:55.825>filter <00:03:55.965>out <00:03:56.105>the <00:03:56.245>even

101
00:03:57.305 --> 00:03:58.865
<00:03:57.305>numbers <00:03:57.538>to <00:03:57.771>keep <00:03:58.005>only <00:03:58.238>the <00:03:58.471>odd <00:03:58.705>ones.

102
00:03:59.085 --> 00:04:00.865
<00:03:59.085>And <00:03:59.285>then <00:03:59.485>finally <00:03:59.685>we <00:03:59.885>wanna <00:04:00.085>find <00:04:00.285>the <00:04:00.485>maximum.

103
00:04:02.635 --> 00:04:03.895
<00:04:02.635>And <00:04:02.797>this <00:04:02.959>is <00:04:03.121>how <00:04:03.283>we <00:04:03.445>could <00:04:03.607>do <00:04:03.769>it

104
00:04:03.895 --> 00:04:05.535
<00:04:03.895>with <00:04:04.175>c <00:04:04.455>plus <00:04:04.735>plus <00:04:05.015>algorithms, <00:04:05.295>right?

105
00:04:05.535 --> 00:04:07.535
<00:04:05.535>So <00:04:05.674>the <00:04:05.815>first <00:04:05.954>step, <00:04:06.095>we <00:04:06.234>compute <00:04:06.375>the <00:04:06.515>magnitude <00:04:06.655>of <00:04:06.795>each <00:04:06.935>number

106
00:04:07.675 --> 00:04:10.575
<00:04:07.675>by <00:04:07.830>calling <00:04:07.986>transform, <00:04:08.141>transform <00:04:08.297>takes <00:04:08.452>a <00:04:08.608>range <00:04:08.763>of <00:04:08.919>inter <00:04:09.075>dose

107
00:04:10.595 --> 00:04:12.415
<00:04:10.595>and <00:04:10.828>pushes <00:04:11.061>them <00:04:11.295>back <00:04:11.528>into <00:04:11.761>another <00:04:11.995>container

108
00:04:12.995 --> 00:04:15.135
<00:04:12.995>by <00:04:13.275>applying <00:04:13.555>this <00:04:13.835>modification <00:04:14.115>function, <00:04:14.395>right?

109
00:04:15.155 --> 00:04:16.335
<00:04:15.155>And <00:04:15.509>this <00:04:15.863>modification <00:04:16.216>function

110
00:04:16.335 --> 00:04:17.415
<00:04:16.334>is <00:04:16.577>the <00:04:16.821>absolute <00:04:17.064>value <00:04:17.307>function.

111
00:04:17.915 --> 00:04:19.415
<00:04:17.915>And <00:04:18.140>now <00:04:18.365>we've <00:04:18.590>got <00:04:18.815>all <00:04:19.040>the <00:04:19.265>magnitudes

112
00:04:19.475 --> 00:04:21.415
<00:04:19.475>and <00:04:19.630>now <00:04:19.786>we <00:04:19.941>wanna <00:04:20.097>filter <00:04:20.252>out <00:04:20.408>only <00:04:20.563>the <00:04:20.719>even <00:04:20.875>numbers

113
00:04:21.435 --> 00:04:22.535
<00:04:21.435>and <00:04:21.632>keep <00:04:21.831>only <00:04:22.029>the <00:04:22.227>odd <00:04:22.425>ones.

114
00:04:22.535 --> 00:04:23.775
<00:04:22.535>And <00:04:22.721>for <00:04:22.907>that <00:04:23.093>we <00:04:23.279>use <00:04:23.465>copy <00:04:23.650>F.

115
00:04:23.955 --> 00:04:25.815
<00:04:23.955>So <00:04:24.188>copy <00:04:24.421>F <00:04:24.655>only <00:04:24.888>copies <00:04:25.121>numbers <00:04:25.354>over

116
00:04:25.815 --> 00:04:27.655
<00:04:25.815>to <00:04:26.048>another <00:04:26.281>container <00:04:26.515>if <00:04:26.748>the <00:04:26.981>predicate <00:04:27.215>matches.

117
00:04:28.035 --> 00:04:30.895
<00:04:28.035>And <00:04:28.190>finally <00:04:28.346>we <00:04:28.501>call <00:04:28.657>max <00:04:28.812>to <00:04:28.968>get <00:04:29.123>the <00:04:29.279>maximum <00:04:29.435>value.

118
00:04:31.155 --> 00:04:33.535
<00:04:31.155>And <00:04:31.310>I'm <00:04:31.466>using <00:04:31.621>the <00:04:31.777>new <00:04:31.932>c <00:04:32.088>plus <00:04:32.243>plus <00:04:32.399>20 <00:04:32.554>algorithms.

119
00:04:33.535 --> 00:04:35.215
<00:04:33.534>So <00:04:33.710>you <00:04:33.885>don't <00:04:34.059>have <00:04:34.234>to <00:04:34.409>specify <00:04:34.585>the <00:04:34.760>iterator <00:04:34.934>here.

120
00:04:35.325 --> 00:04:36.935
<00:04:35.325>This <00:04:35.791>all <00:04:36.258>happens, <00:04:36.724>right?

121
00:04:37.445 --> 00:04:39.775
<00:04:37.445>However, <00:04:37.678>this <00:04:37.911>isn't <00:04:38.145>a <00:04:38.378>particularly <00:04:38.611>nice <00:04:38.844>solution

122
00:04:39.775 --> 00:04:41.335
<00:04:39.775>because <00:04:40.054>while <00:04:40.335>we <00:04:40.614>are <00:04:40.895>doing <00:04:41.174>composition,

123
00:04:41.345 --> 00:04:42.695
<00:04:41.345>we're <00:04:41.750>doing <00:04:42.155>eager <00:04:42.560>composition,

124
00:04:42.915 --> 00:04:44.935
<00:04:42.915>we <00:04:43.148>are <00:04:43.381>creating <00:04:43.615>all <00:04:43.848>these <00:04:44.081>intermediate <00:04:44.315>containers.

125
00:04:45.315 --> 00:04:47.335
<00:04:45.315>We <00:04:45.548>eagerly <00:04:45.781>compute <00:04:46.015>all <00:04:46.248>the <00:04:46.481>intermediate <00:04:46.715>results

126
00:04:47.445 --> 00:04:48.495
<00:04:47.445>even <00:04:47.634>if <00:04:47.823>we <00:04:48.012>never <00:04:48.201>need <00:04:48.390>them.

127
00:04:48.715 --> 00:04:49.815
<00:04:48.715>And <00:04:48.913>we <00:04:49.111>still <00:04:49.309>have <00:04:49.507>to <00:04:49.705>deal

128
00:04:49.815 --> 00:04:51.655
<00:04:49.815>with <00:04:50.165>this <00:04:50.515>manual <00:04:50.865>intermediate <00:04:51.215>state.

129
00:04:52.395 --> 00:04:55.175
<00:04:52.395>So <00:04:52.522>the <00:04:52.649>better <00:04:52.776>way <00:04:52.904>to <00:04:53.031>do <00:04:53.158>it <00:04:53.285>is <00:04:53.413>to <00:04:53.540>use <00:04:53.667>lazy <00:04:53.794>composition.

130
00:04:55.795 --> 00:04:56.935
<00:04:55.795>And <00:04:56.137>for <00:04:56.479>lazy <00:04:56.821>composition,

131
00:04:56.955 --> 00:04:59.095
<00:04:56.955>we <00:04:57.130>also <00:04:57.305>used <00:04:57.479>new <00:04:57.655>c <00:04:57.830>plus <00:04:58.005>plus <00:04:58.180>20 <00:04:58.354>views.

132
00:04:59.715 --> 00:05:01.535
<00:04:59.715>So <00:04:59.948>view <00:05:00.181>is <00:05:00.415>essentially <00:05:00.648>a <00:05:00.881>lazy <00:05:01.115>range.

133
00:05:02.045 --> 00:05:04.455
<00:05:02.045>It's <00:05:02.200>just <00:05:02.356>a <00:05:02.511>description <00:05:02.667>of <00:05:02.822>how <00:05:02.978>we <00:05:03.133>compute <00:05:03.289>some <00:05:03.445>values.

134
00:05:05.155 --> 00:05:06.175
<00:05:05.155>And <00:05:05.338>when <00:05:05.522>you <00:05:05.705>create <00:05:05.889>a <00:05:06.073>view

135
00:05:06.175 --> 00:05:07.895
<00:05:06.175>or <00:05:06.330>when <00:05:06.486>you <00:05:06.641>compose <00:05:06.797>a <00:05:06.952>view, <00:05:07.108>this <00:05:07.263>does <00:05:07.419>nothing <00:05:07.575>yet.

136
00:05:08.405 --> 00:05:10.255
<00:05:08.405>It's <00:05:08.604>just <00:05:08.804>the <00:05:09.005>description <00:05:09.205>of <00:05:09.405>what <00:05:09.604>you <00:05:09.804>need

137
00:05:10.295 --> 00:05:11.375
<00:05:10.295>to <00:05:10.433>do <00:05:10.572>in <00:05:10.711>order <00:05:10.850>to <00:05:10.989>get <00:05:11.128>the <00:05:11.267>data.

138
00:05:11.795 --> 00:05:14.455
<00:05:11.795>And <00:05:11.950>only <00:05:12.106>when <00:05:12.261>you <00:05:12.417>start <00:05:12.572>iterating <00:05:12.728>will <00:05:12.883>you <00:05:13.039>trigger <00:05:13.195>the

139
00:05:14.455 --> 00:05:15.615
<00:05:14.455>computation <00:05:14.977>and <00:05:15.499>only

140
00:05:15.755 --> 00:05:18.175
<00:05:15.755>as <00:05:15.895>you <00:05:16.034>iterate <00:05:16.175>them <00:05:16.315>lazily <00:05:16.455>as <00:05:16.594>far <00:05:16.735>as <00:05:16.875>you <00:05:17.015>need <00:05:17.155>them.

141
00:05:18.635 --> 00:05:20.895
<00:05:18.635>And <00:05:18.835>this <00:05:19.034>leads <00:05:19.235>to <00:05:19.435>very <00:05:19.635>simple <00:05:19.835>functional <00:05:20.034>pipeline

142
00:05:20.895 --> 00:05:22.055
<00:05:20.895>style <00:05:21.068>where <00:05:21.243>we <00:05:21.417>don't <00:05:21.591>have <00:05:21.765>any <00:05:21.939>state.

143
00:05:24.725 --> 00:05:26.105
<00:05:24.725>So <00:05:24.902>here's <00:05:25.079>how <00:05:25.257>we <00:05:25.434>do <00:05:25.612>it <00:05:25.789>using <00:05:25.967>views.

144
00:05:26.605 --> 00:05:28.185
<00:05:26.605>So <00:05:26.885>instead <00:05:27.165>of <00:05:27.445>the <00:05:27.725>transform <00:05:28.005>algorithm,

145
00:05:28.365 --> 00:05:29.585
<00:05:28.365>use <00:05:28.731>the <00:05:29.097>transform <00:05:29.462>view.

146
00:05:30.245 --> 00:05:32.145
<00:05:30.245>And <00:05:30.525>this <00:05:30.805>first <00:05:31.085>line <00:05:31.365>simply <00:05:31.645>describes

147
00:05:32.145 --> 00:05:33.665
<00:05:32.145>that <00:05:32.486>magnitude <00:05:32.829>is <00:05:33.171>the <00:05:33.513>range.

148
00:05:34.085 --> 00:05:36.185
<00:05:34.085>By <00:05:34.284>applying <00:05:34.484>this <00:05:34.685>transformation <00:05:34.885>function <00:05:35.085>to <00:05:35.284>each <00:05:35.484>element,

149
00:05:36.445 --> 00:05:39.025
<00:05:36.445>but <00:05:36.600>it <00:05:36.756>doesn't <00:05:36.911>do <00:05:37.067>anything <00:05:37.222>yet, <00:05:37.378>it <00:05:37.533>just <00:05:37.689>the <00:05:37.844>description.

150
00:05:39.695 --> 00:05:42.385
<00:05:39.695>Then <00:05:39.835>we <00:05:39.974>say, <00:05:40.115>okay, <00:05:40.255>we <00:05:40.395>wanna <00:05:40.534>filter <00:05:40.675>out <00:05:40.815>the <00:05:40.955>even <00:05:41.094>numbers

151
00:05:42.605 --> 00:05:43.825
<00:05:42.605>and <00:05:42.824>keep <00:05:43.044>only <00:05:43.263>the <00:05:43.483>odd <00:05:43.703>ones.

152
00:05:44.405 --> 00:05:46.785
<00:05:44.405>So <00:05:44.604>we <00:05:44.804>uh, <00:05:45.005>use <00:05:45.205>the <00:05:45.405>filter <00:05:45.604>algorithm, <00:05:45.804>uh,

153
00:05:46.785 --> 00:05:47.945
<00:05:46.784>filter <00:05:47.046>view <00:05:47.306>for <00:05:47.568>this <00:05:47.829>case.

154
00:05:48.055 --> 00:05:49.905
<00:05:48.055>This <00:05:48.230>is <00:05:48.405>the <00:05:48.580>equivalent <00:05:48.755>to <00:05:48.930>the <00:05:49.105>copy <00:05:49.280>of <00:05:49.455>algorithm.

155
00:05:50.605 --> 00:05:51.945
<00:05:50.605>And <00:05:50.846>again, <00:05:51.087>this <00:05:51.328>does <00:05:51.569>nothing <00:05:51.811>yet.

156
00:05:51.945 --> 00:05:54.585
<00:05:51.945>It <00:05:52.224>simply <00:05:52.505>um, <00:05:52.784>increases <00:05:53.065>the <00:05:53.344>pipeline

157
00:05:54.645 --> 00:05:55.785
<00:05:54.645>by <00:05:54.901>adding <00:05:55.157>an <00:05:55.414>additional <00:05:55.671>step.

158
00:05:56.085 --> 00:05:57.965
<00:05:56.085>And <00:05:56.284>then <00:05:56.484>finally <00:05:56.685>we <00:05:56.885>wanna <00:05:57.085>use <00:05:57.284>the <00:05:57.484>maximum.

159
00:05:58.305 --> 00:06:00.005
<00:05:58.305>And <00:05:58.505>here <00:05:58.705>we <00:05:58.905>still <00:05:59.105>use <00:05:59.305>the <00:05:59.505>max <00:05:59.705>algorithm

160
00:06:00.345 --> 00:06:03.405
<00:06:00.345>and <00:06:00.485>Max <00:06:00.625>will <00:06:00.765>now <00:06:00.905>go <00:06:01.045>over <00:06:01.185>and <00:06:01.325>start <00:06:01.465>iterating <00:06:01.605>over <00:06:01.745>overviews.

161
00:06:03.665 --> 00:06:06.125
<00:06:03.665>And <00:06:03.820>as <00:06:03.976>it <00:06:04.131>does, <00:06:04.287>so <00:06:04.442>it'll <00:06:04.598>apply <00:06:04.753>the <00:06:04.909>transformation <00:06:05.065>function

162
00:06:06.125 --> 00:06:08.205
<00:06:06.125>to <00:06:06.325>each <00:06:06.525>element <00:06:06.725>and <00:06:06.925>it'll <00:06:07.125>skip <00:06:07.325>over <00:06:07.525>elements

163
00:06:08.205 --> 00:06:09.885
<00:06:08.205>that <00:06:08.484>don't <00:06:08.765>match <00:06:09.044>the <00:06:09.325>filter, <00:06:09.604>right?

164
00:06:09.915 --> 00:06:11.685
<00:06:09.915>Only <00:06:10.115>the <00:06:10.315>last <00:06:10.515>line <00:06:10.715>actually <00:06:10.915>does <00:06:11.115>any <00:06:11.315>code.

165
00:06:11.945 --> 00:06:14.165
<00:06:11.945>The <00:06:12.178>first <00:06:12.411>two <00:06:12.645>just <00:06:12.878>describe <00:06:13.111>the <00:06:13.344>pipeline

166
00:06:15.025 --> 00:06:15.845
<00:06:15.025>and <00:06:15.209>now <00:06:15.394>we <00:06:15.578>might <00:06:15.763>say,

167
00:06:15.845 --> 00:06:17.045
<00:06:15.845>okay, <00:06:15.999>we <00:06:16.153>still <00:06:16.307>have <00:06:16.462>the <00:06:16.616>state <00:06:16.770>in <00:06:16.925>there.

168
00:06:17.065 --> 00:06:19.005
<00:06:17.065>And <00:06:17.265>functioning <00:06:17.465>programming <00:06:17.665>is <00:06:17.865>supposed <00:06:18.065>to <00:06:18.265>eliminate <00:06:18.465>state,

169
00:06:19.145 --> 00:06:20.165
<00:06:19.145>but <00:06:19.374>it's <00:06:19.604>not <00:06:19.833>really <00:06:20.063>state.

170
00:06:20.505 --> 00:06:22.525
<00:06:20.505>The <00:06:20.738>local <00:06:20.971>variables <00:06:21.205>there <00:06:21.438>are <00:06:21.671>simply <00:06:21.905>labeled

171
00:06:22.665 --> 00:06:23.845
<00:06:22.665>for <00:06:22.930>parts <00:06:23.196>of <00:06:23.461>the <00:06:23.727>pipelines.

172
00:06:24.305 --> 00:06:26.925
<00:06:24.305>And <00:06:24.460>the <00:06:24.616>more <00:06:24.771>idiomatic <00:06:24.927>way <00:06:25.082>is <00:06:25.238>to <00:06:25.393>eliminate <00:06:25.549>them <00:06:25.705>altogether

173
00:06:27.305 --> 00:06:28.365
<00:06:27.305>and <00:06:27.495>just <00:06:27.686>write <00:06:27.877>it <00:06:28.068>like <00:06:28.259>this.

174
00:06:28.665 --> 00:06:30.525
<00:06:28.665>So <00:06:28.840>we <00:06:29.015>say <00:06:29.190>the <00:06:29.365>biggest <00:06:29.540>odd <00:06:29.715>magnitude <00:06:29.890>is <00:06:30.065>given

175
00:06:30.525 --> 00:06:32.485
<00:06:30.525>by <00:06:30.724>taking <00:06:30.924>our <00:06:31.125>range, <00:06:31.325>we <00:06:31.525>are <00:06:31.724>transforming <00:06:31.924>it,

176
00:06:32.575 --> 00:06:34.885
<00:06:32.575>we're <00:06:32.750>filtering <00:06:32.925>it <00:06:33.099>and <00:06:33.275>they're <00:06:33.450>applying <00:06:33.625>it <00:06:33.800>to <00:06:33.974>mix.

177
00:06:35.985 --> 00:06:37.405
<00:06:35.985>And <00:06:36.240>here <00:06:36.496>we <00:06:36.751>can <00:06:37.007>see <00:06:37.263>uh,

178
00:06:37.505 --> 00:06:39.285
<00:06:37.505>two <00:06:37.855>very <00:06:38.205>powerful <00:06:38.555>composition <00:06:38.905>patterns

179
00:06:39.535 --> 00:06:40.805
<00:06:39.534>using <00:06:39.916>transform <00:06:40.296>and <00:06:40.678>filter.

180
00:06:40.905 --> 00:06:43.605
<00:06:40.905>We <00:06:41.032>can <00:06:41.159>take <00:06:41.286>a <00:06:41.414>range <00:06:41.541>and <00:06:41.668>lazily <00:06:41.795>transform <00:06:41.923>it <00:06:42.050>into <00:06:42.177>some <00:06:42.304>other

181
00:06:43.605 --> 00:06:45.565
<00:06:43.605>range <00:06:43.955>either <00:06:44.305>by <00:06:44.655>skipping <00:06:45.005>elements

182
00:06:45.565 --> 00:06:46.925
<00:06:45.565>or <00:06:45.769>by <00:06:45.973>changing <00:06:46.177>them <00:06:46.381>and <00:06:46.585>so <00:06:46.789>on.

183
00:06:47.265 --> 00:06:48.565
<00:06:47.265>And <00:06:47.498>then <00:06:47.733>with <00:06:47.967>the <00:06:48.201>mix <00:06:48.435>algorithm,

184
00:06:48.705 --> 00:06:49.925
<00:06:48.705>we <00:06:48.924>can <00:06:49.144>actually <00:06:49.363>take <00:06:49.583>a <00:06:49.803>range

185
00:06:49.945 --> 00:06:51.805
<00:06:49.945>and <00:06:50.145>compute <00:06:50.344>a <00:06:50.545>single <00:06:50.745>element <00:06:50.945>out <00:06:51.145>of <00:06:51.344>them.

186
00:06:55.985 --> 00:06:57.445
<00:06:55.985>So <00:06:56.149>let's <00:06:56.313>take <00:06:56.477>a <00:06:56.642>look <00:06:56.806>at <00:06:56.970>the <00:06:57.134>next <00:06:57.299>problem.

187
00:06:57.945 --> 00:06:59.205
<00:06:57.945>So <00:06:58.134>you <00:06:58.323>here <00:06:58.512>we're <00:06:58.700>having <00:06:58.890>two <00:06:59.079>lists

188
00:06:59.305 --> 00:07:00.405
<00:06:59.305>and <00:06:59.503>we <00:06:59.701>want <00:06:59.899>a <00:07:00.097>number <00:07:00.294>target

189
00:07:01.025 --> 00:07:03.045
<00:07:01.025>and <00:07:01.164>we <00:07:01.304>want <00:07:01.445>to <00:07:01.585>get <00:07:01.724>two <00:07:01.864>into <00:07:02.005>just <00:07:02.145>one <00:07:02.284>from <00:07:02.424>each

190
00:07:03.045 --> 00:07:04.285
<00:07:03.045>list, <00:07:03.324>whose <00:07:03.603>sum <00:07:03.882>is <00:07:04.161>target.

191
00:07:05.985 --> 00:07:07.525
<00:07:05.985>So <00:07:06.183>for <00:07:06.381>example, <00:07:06.579>if <00:07:06.777>those <00:07:06.974>are <00:07:07.173>two <00:07:07.371>list

192
00:07:07.545 --> 00:07:09.925
<00:07:07.545>and <00:07:07.685>the <00:07:07.825>target <00:07:07.965>is <00:07:08.105>12, <00:07:08.245>then <00:07:08.385>the <00:07:08.525>output <00:07:08.665>would <00:07:08.805>be <00:07:08.945>four

193
00:07:09.945 --> 00:07:12.125
<00:07:09.945>and <00:07:10.145>eight <00:07:10.344>because <00:07:10.545>four <00:07:10.745>plus <00:07:10.945>eight <00:07:11.145>equals <00:07:11.344>12.

194
00:07:13.795 --> 00:07:15.415
<00:07:13.795>And <00:07:14.028>I'm <00:07:14.261>gonna <00:07:14.495>skip <00:07:14.728>the <00:07:14.961>imperative <00:07:15.195>code.

195
00:07:16.155 --> 00:07:19.335
<00:07:16.155>Um, <00:07:16.271>I <00:07:16.388>think <00:07:16.505>you <00:07:16.621>can <00:07:16.738>all <00:07:16.854>uh, <00:07:16.971>bite <00:07:17.088>this <00:07:17.205>the <00:07:17.321>very <00:07:17.438>naive <00:07:17.554>way.

196
00:07:19.675 --> 00:07:21.815
<00:07:19.675>So <00:07:19.875>let's <00:07:20.075>think <00:07:20.275>about <00:07:20.475>the <00:07:20.675>composition <00:07:20.875>instead <00:07:21.075>directly.

197
00:07:22.395 --> 00:07:23.415
<00:07:22.395>So <00:07:22.624>what <00:07:22.854>is <00:07:23.083>the <00:07:23.313>composition?

198
00:07:23.605 --> 00:07:25.615
<00:07:23.605>Well, <00:07:23.780>we <00:07:23.955>wanna <00:07:24.130>find <00:07:24.305>a <00:07:24.480>pair <00:07:24.655>that <00:07:24.830>finds <00:07:25.005>something.

199
00:07:25.755 --> 00:07:27.375
<00:07:25.755>So <00:07:25.930>first <00:07:26.105>we <00:07:26.280>need <00:07:26.455>to <00:07:26.630>generate <00:07:26.805>all <00:07:26.980>the <00:07:27.155>pairs

200
00:07:27.435 --> 00:07:29.775
<00:07:27.435>and <00:07:27.562>then <00:07:27.689>we <00:07:27.816>need <00:07:27.944>to <00:07:28.071>find <00:07:28.198>the <00:07:28.325>pair <00:07:28.453>that <00:07:28.580>sum <00:07:28.707>is <00:07:28.835>target.

201
00:07:31.115 --> 00:07:33.295
<00:07:31.115>And <00:07:31.315>we <00:07:31.515>again <00:07:31.715>use <00:07:31.915>lazy <00:07:32.115>composition <00:07:32.315>using <00:07:32.515>views.

202
00:07:34.275 --> 00:07:35.335
<00:07:34.275>And <00:07:34.465>this <00:07:34.656>can <00:07:34.847>look <00:07:35.038>like <00:07:35.229>this.

203
00:07:35.715 --> 00:07:38.375
<00:07:35.715>So <00:07:35.870>Cartesian <00:07:36.026>product <00:07:36.181>is <00:07:36.337>a <00:07:36.492>view <00:07:36.648>that <00:07:36.803>takes <00:07:36.959>multiple <00:07:37.115>ranges

204
00:07:38.395 --> 00:07:41.615
<00:07:38.395>and <00:07:38.570>returns <00:07:38.745>to <00:07:38.919>Cartesian <00:07:39.094>product <00:07:39.270>IE <00:07:39.445>all <00:07:39.620>potential <00:07:39.794>pairs

205
00:07:41.615 --> 00:07:43.775
<00:07:41.615>or <00:07:41.815>triples <00:07:42.015>or <00:07:42.215>triples <00:07:42.415>of <00:07:42.615>the <00:07:42.815>input <00:07:43.015>ranges.

206
00:07:44.235 --> 00:07:45.895
<00:07:44.235>And <00:07:44.410>now <00:07:44.585>we've <00:07:44.760>got <00:07:44.935>them <00:07:45.110>and <00:07:45.285>remember <00:07:45.460>this <00:07:45.635>is

207
00:07:45.895 --> 00:07:47.175
<00:07:45.895>lazy, <00:07:46.183>this <00:07:46.471>doesn't <00:07:46.759>do <00:07:47.047>anything.

208
00:07:47.275 --> 00:07:50.175
<00:07:47.275>It <00:07:47.430>doesn't <00:07:47.586>like <00:07:47.741>allocate <00:07:47.897>our <00:07:48.052>n <00:07:48.208>squared <00:07:48.363>memory <00:07:48.519>or <00:07:48.674>something.

209
00:07:50.255 --> 00:07:51.895
<00:07:50.255>It's <00:07:50.488>just <00:07:50.721>a <00:07:50.955>description <00:07:51.188>of <00:07:51.421>the <00:07:51.655>thing.

210
00:07:52.435 --> 00:07:53.895
<00:07:52.435>And <00:07:52.622>then <00:07:52.810>we <00:07:52.998>pass <00:07:53.185>that <00:07:53.373>to <00:07:53.561>find <00:07:53.748>of

211
00:07:54.155 --> 00:07:55.495
<00:07:54.155>and <00:07:54.356>in <00:07:54.556>find <00:07:54.758>of <00:07:54.959>we <00:07:55.159>say <00:07:55.361>hey,

212
00:07:55.755 --> 00:07:58.615
<00:07:55.755>we <00:07:55.910>wanna <00:07:56.066>find <00:07:56.221>the <00:07:56.377>given <00:07:56.532>combination <00:07:56.688>with <00:07:56.843>sum <00:07:56.999>is <00:07:57.155>equal

213
00:07:58.615 --> 00:07:59.655
<00:07:58.615>to <00:07:59.082>target, <00:07:59.551>right?

214
00:07:59.655 --> 00:08:00.815
<00:07:59.655>So <00:07:59.828>it's <00:08:00.003>a <00:08:00.176>twofold. <00:08:00.351>So <00:08:00.525>we <00:08:00.699>have

215
00:08:00.815 --> 00:08:02.535
<00:08:00.815>to <00:08:00.970>use <00:08:01.126>this <00:08:01.281>ugly <00:08:01.437>get <00:08:01.592>in <00:08:01.748>there <00:08:01.903>but <00:08:02.059>it's <00:08:02.215>fine.

216
00:08:03.035 --> 00:08:04.535
<00:08:03.035>And <00:08:03.227>then <00:08:03.420>find <00:08:03.613>theft <00:08:03.806>gives <00:08:03.999>us <00:08:04.192>an <00:08:04.385>iterator.

217
00:08:04.555 --> 00:08:06.015
<00:08:04.555>And <00:08:04.742>so <00:08:04.930>we <00:08:05.118>wanna <00:08:05.305>map <00:08:05.493>that <00:08:05.681>on <00:08:05.869>optional.

218
00:08:06.355 --> 00:08:07.815
<00:08:06.355>Um, <00:08:06.542>it's <00:08:06.730>a <00:08:06.918>bit <00:08:07.105>ugly <00:08:07.293>but <00:08:07.481>it <00:08:07.669>works.

219
00:08:08.995 --> 00:08:10.695
<00:08:08.995>And <00:08:09.345>remember, <00:08:09.695>only <00:08:10.045>the <00:08:10.395>find

220
00:08:10.695 --> 00:08:12.335
<00:08:10.695>of <00:08:10.974>call <00:08:11.255>actually <00:08:11.534>executes <00:08:11.815>any <00:08:12.094>code.

221
00:08:12.475 --> 00:08:15.135
<00:08:12.475>The <00:08:12.675>first <00:08:12.875>line <00:08:13.075>simply <00:08:13.275>describes <00:08:13.475>the <00:08:13.675>pipeline, <00:08:13.875>right?

222
00:08:15.355 --> 00:08:17.095
<00:08:15.355>So <00:08:15.555>the <00:08:15.755>find <00:08:15.955>of <00:08:16.155>will <00:08:16.355>iterate <00:08:16.555>over <00:08:16.755>them

223
00:08:17.155 --> 00:08:18.375
<00:08:17.155>and <00:08:17.429>it'll <00:08:17.704>iterate <00:08:17.978>over <00:08:18.253>them

224
00:08:18.375 --> 00:08:20.495
<00:08:18.375>and <00:08:18.575>generate <00:08:18.775>the <00:08:18.975>pairs <00:08:19.175>on <00:08:19.375>demand <00:08:19.575>without <00:08:19.775>doing

225
00:08:20.495 --> 00:08:21.535
<00:08:20.495>any <00:08:20.963>memory <00:08:21.431>allocation.

226
00:08:21.795 --> 00:08:24.095
<00:08:21.795>Um, <00:08:22.028>it's <00:08:22.261>just <00:08:22.495>smart <00:08:22.728>combination <00:08:22.961>of <00:08:23.195>iterators

227
00:08:25.635 --> 00:08:28.375
<00:08:25.635>and <00:08:25.790>our <00:08:25.946>set <00:08:26.101>functional <00:08:26.257>programming <00:08:26.412>is <00:08:26.568>very <00:08:26.723>easy <00:08:26.879>to <00:08:27.034>paralyze.

228
00:08:28.675 --> 00:08:29.735
<00:08:28.675>Um, <00:08:28.811>and <00:08:28.947>I <00:08:29.083>can <00:08:29.220>prove <00:08:29.356>it <00:08:29.492>to <00:08:29.629>you

229
00:08:29.735 --> 00:08:30.975
<00:08:29.735>because <00:08:29.958>in <00:08:30.181>c <00:08:30.404>plus <00:08:30.627>plus <00:08:30.851>26,

230
00:08:31.205 --> 00:08:32.775
<00:08:31.205>like <00:08:31.405>this <00:08:31.604>is <00:08:31.805>an <00:08:32.005>O <00:08:32.204>one <00:08:32.405>squared <00:08:32.605>algorithm.

231
00:08:32.955 --> 00:08:35.175
<00:08:32.955>So <00:08:33.082>there's <00:08:33.209>a <00:08:33.336>lot <00:08:33.464>of <00:08:33.591>data, <00:08:33.718>it <00:08:33.845>makes <00:08:33.973>sense <00:08:34.100>to <00:08:34.227>paralyze <00:08:34.355>it

232
00:08:35.275 --> 00:08:37.415
<00:08:35.275>and <00:08:35.449>in <00:08:35.625>c <00:08:35.799>plus <00:08:35.975>plus <00:08:36.150>26 <00:08:36.324>the <00:08:36.500>upcoming <00:08:36.674>standard,

233
00:08:37.715 --> 00:08:38.975
<00:08:37.715>you <00:08:37.941>can <00:08:38.168>just <00:08:38.395>change <00:08:38.622>one <00:08:38.849>line

234
00:08:39.075 --> 00:08:41.655
<00:08:39.075>and <00:08:39.215>instead <00:08:39.355>of <00:08:39.495>say <00:08:39.635>it's <00:08:39.775>calling <00:08:39.915>fef, <00:08:40.055>you <00:08:40.195>could <00:08:40.335>find <00:08:40.475>F

235
00:08:41.655 --> 00:08:42.855
<00:08:41.655>and <00:08:41.871>say <00:08:42.087>I <00:08:42.303>want <00:08:42.519>it <00:08:42.735>paralleled.

236
00:08:43.315 --> 00:08:45.055
<00:08:43.315>And <00:08:43.548>this <00:08:43.781>is <00:08:44.015>now <00:08:44.248>a <00:08:44.481>parallel <00:08:44.715>algorithm

237
00:08:45.085 --> 00:08:47.615
<00:08:45.085>that <00:08:45.260>will <00:08:45.435>iterate <00:08:45.610>over <00:08:45.785>all <00:08:45.960>the <00:08:46.135>pairs <00:08:46.310>in <00:08:46.485>parallel

238
00:08:47.635 --> 00:08:49.815
<00:08:47.635>and <00:08:47.835>compute <00:08:48.035>the <00:08:48.235>range <00:08:48.435>by <00:08:48.635>subdividing <00:08:48.835>it <00:08:49.035>into

239
00:08:50.055 --> 00:08:51.095
<00:08:50.055>multiple <00:08:50.289>threats <00:08:50.523>and <00:08:50.757>so <00:08:50.991>on.

240
00:08:51.165 --> 00:08:52.975
<00:08:51.165>Very <00:08:51.515>easy. <00:08:51.865>And <00:08:52.214>this <00:08:52.564>is

241
00:08:52.975 --> 00:08:55.445
<00:08:52.975>because <00:08:53.150>we <00:08:53.325>simply <00:08:53.500>described <00:08:53.675>our <00:08:53.850>problem <00:08:54.025>statement <00:08:54.200>in <00:08:54.375>a

242
00:08:55.445 --> 00:08:57.365
<00:08:55.445>declarative <00:08:55.620>way <00:08:55.795>and <00:08:55.970>then <00:08:56.145>we <00:08:56.320>can <00:08:56.495>just <00:08:56.670>say, <00:08:56.845>hey,

243
00:08:57.365 --> 00:08:58.525
<00:08:57.365>please <00:08:57.626>solve <00:08:57.887>it <00:08:58.148>in <00:08:58.409>parallel.

244
00:08:58.625 --> 00:09:00.125
<00:08:58.625>And <00:08:58.850>now <00:08:59.075>it <00:08:59.300>works <00:08:59.525>in <00:08:59.750>parallel, <00:08:59.975>right?

245
00:09:00.545 --> 00:09:02.485
<00:09:00.545>Um, <00:09:00.824>and <00:09:01.104>this <00:09:01.385>is <00:09:01.665>really <00:09:01.944>powerful

246
00:09:03.945 --> 00:09:06.085
<00:09:03.945>but <00:09:04.120>of <00:09:04.295>course <00:09:04.470>it's <00:09:04.645>still <00:09:04.820>an <00:09:04.995>o <00:09:05.170>squared <00:09:05.345>algorithm

247
00:09:06.305 --> 00:09:07.645
<00:09:06.305>and <00:09:06.477>if <00:09:06.649>you're <00:09:06.821>doing <00:09:06.994>a <00:09:07.166>lead <00:09:07.338>code <00:09:07.511>problem,

248
00:09:07.745 --> 00:09:09.125
<00:09:07.745>you <00:09:07.993>probably <00:09:08.241>want <00:09:08.490>the <00:09:08.738>linear <00:09:08.987>solution.

249
00:09:09.425 --> 00:09:11.045
<00:09:09.425>Um, <00:09:09.658>so <00:09:09.891>use <00:09:10.125>a <00:09:10.358>hash <00:09:10.591>table, <00:09:10.824>right?

250
00:09:11.625 --> 00:09:14.525
<00:09:11.625>Um, <00:09:11.780>and <00:09:11.936>we <00:09:12.091>can <00:09:12.247>also <00:09:12.402>use <00:09:12.558>the <00:09:12.713>views <00:09:12.869>for <00:09:13.025>that.

251
00:09:14.545 --> 00:09:16.565
<00:09:14.545>So <00:09:14.700>we <00:09:14.856>say, <00:09:15.011>okay, <00:09:15.167>first <00:09:15.322>we <00:09:15.478>take <00:09:15.633>the <00:09:15.789>first <00:09:15.944>range

252
00:09:16.585 --> 00:09:18.965
<00:09:16.585>and <00:09:16.785>combine <00:09:16.985>that <00:09:17.185>into <00:09:17.385>like <00:09:17.585>an <00:09:17.785>that's <00:09:17.985>it.

253
00:09:19.025 --> 00:09:20.045
<00:09:19.025>And <00:09:19.178>now <00:09:19.331>we've <00:09:19.483>got <00:09:19.637>the <00:09:19.790>hash <00:09:19.943>table

254
00:09:20.065 --> 00:09:21.245
<00:09:20.065>and <00:09:20.242>then <00:09:20.419>we <00:09:20.596>still <00:09:20.773>use <00:09:20.950>find <00:09:21.127>F,

255
00:09:21.465 --> 00:09:23.325
<00:09:21.465>but <00:09:21.640>now <00:09:21.815>we <00:09:21.990>iterate <00:09:22.165>only <00:09:22.340>over <00:09:22.515>one <00:09:22.690>of <00:09:22.865>them

256
00:09:23.345 --> 00:09:25.045
<00:09:23.345>and <00:09:23.545>look <00:09:23.745>up <00:09:23.945>in <00:09:24.145>the <00:09:24.345>hash <00:09:24.545>table, <00:09:24.745>right?

257
00:09:25.065 --> 00:09:27.165
<00:09:25.065>And <00:09:25.265>this <00:09:25.465>is <00:09:25.665>no <00:09:25.865>longer <00:09:26.065>pure <00:09:26.265>functional <00:09:26.465>code.

258
00:09:27.165 --> 00:09:28.565
<00:09:27.165>We've <00:09:27.305>got <00:09:27.444>the <00:09:27.585>state <00:09:27.725>in <00:09:27.865>there, <00:09:28.005>we've <00:09:28.145>got <00:09:28.285>the <00:09:28.425>hash

259
00:09:28.565 --> 00:09:29.845
<00:09:28.565>table, <00:09:28.757>but <00:09:28.949>this <00:09:29.141>is <00:09:29.333>C <00:09:29.525>plus <00:09:29.717>pass.

260
00:09:29.845 --> 00:09:31.765
<00:09:29.845>It's <00:09:30.045>fine, <00:09:30.245>right? <00:09:30.445>And <00:09:30.645>you <00:09:30.845>might <00:09:31.045>still <00:09:31.245>be,

261
00:09:31.885 --> 00:09:34.485
<00:09:31.885>and <00:09:32.025>you <00:09:32.165>can <00:09:32.305>still <00:09:32.444>use <00:09:32.585>like <00:09:32.725>a <00:09:32.865>parallel <00:09:33.005>for <00:09:33.145>each, <00:09:33.285>um,

262
00:09:34.745 --> 00:09:36.405
<00:09:34.745>in <00:09:34.945>the <00:09:35.145>fine <00:09:35.345>earth <00:09:35.545>to <00:09:35.745>make <00:09:35.945>it <00:09:36.145>paralyzed.

263
00:09:36.405 --> 00:09:38.405
<00:09:36.405>And <00:09:36.560>then <00:09:36.716>you've <00:09:36.871>got <00:09:37.027>an <00:09:37.182>oh <00:09:37.338>one <00:09:37.493>paralyzed <00:09:37.649>all <00:09:37.805>good.

264
00:09:39.065 --> 00:09:41.525
<00:09:39.065>So <00:09:39.240>it's <00:09:39.415>really <00:09:39.590>powerful <00:09:39.765>once <00:09:39.940>we've <00:09:40.115>strapped <00:09:40.290>it <00:09:40.465>away

265
00:09:41.545 --> 00:09:42.605
<00:09:41.545>in <00:09:41.783>the <00:09:42.021>stick <00:09:42.260>layer <00:09:42.499>style.

266
00:09:47.735 --> 00:09:50.115
<00:09:47.735>Now <00:09:47.862>for <00:09:47.989>the <00:09:48.116>next <00:09:48.244>problem, <00:09:48.371>I've <00:09:48.498>got <00:09:48.625>the <00:09:48.753>single <00:09:48.880>list <00:09:49.007>of <00:09:49.135>indu

267
00:09:50.115 --> 00:09:52.235
<00:09:50.115>and <00:09:50.290>now <00:09:50.465>I <00:09:50.640>want <00:09:50.815>to <00:09:50.990>find <00:09:51.165>the <00:09:51.340>longest <00:09:51.515>contiguous

268
00:09:52.235 --> 00:09:53.515
<00:09:52.235>subsequence <00:09:52.619>of <00:09:53.003>increasing <00:09:53.387>numbers.

269
00:09:54.775 --> 00:09:57.395
<00:09:54.775>So <00:09:54.891>if <00:09:55.008>this <00:09:55.125>is <00:09:55.241>our <00:09:55.358>list <00:09:55.475>of <00:09:55.591>introduc, <00:09:55.708>the <00:09:55.824>output <00:09:55.941>would <00:09:56.058>be <00:09:56.175>four

270
00:09:57.395 --> 00:10:00.755
<00:09:57.395>because <00:09:57.535>the <00:09:57.675>subsequent <00:09:57.814>2, <00:09:57.954>4, <00:09:58.095>5, <00:09:58.235>7 <00:09:58.375>is <00:09:58.515>the <00:09:58.655>longest <00:09:58.795>contiguous

271
00:10:00.755 --> 00:10:02.355
<00:10:00.755>subsequence <00:10:00.988>where <00:10:01.221>all <00:10:01.455>the <00:10:01.688>numbers <00:10:01.921>are <00:10:02.155>increasing.

272
00:10:03.485 --> 00:10:05.385
<00:10:03.485>And <00:10:03.640>again, <00:10:03.796>what's <00:10:03.951>the <00:10:04.107>question <00:10:04.262>you <00:10:04.418>need <00:10:04.573>to <00:10:04.729>ask <00:10:04.885>yourself?

273
00:10:05.815 --> 00:10:07.065
<00:10:05.815>What <00:10:06.096>is <00:10:06.377>the <00:10:06.658>composition <00:10:06.940>here?

274
00:10:07.535 --> 00:10:10.025
<00:10:07.535>Well, <00:10:07.690>the <00:10:07.846>composition <00:10:08.001>is <00:10:08.157>we <00:10:08.312>wanna <00:10:08.468>split <00:10:08.623>our <00:10:08.779>list <00:10:08.935>into

275
00:10:10.225 --> 00:10:11.385
<00:10:10.225>multiple <00:10:10.486>chunks <00:10:10.747>of <00:10:11.008>increasing <00:10:11.269>numbers

276
00:10:11.685 --> 00:10:13.825
<00:10:11.685>and <00:10:11.885>then <00:10:12.084>we've <00:10:12.285>got <00:10:12.484>all <00:10:12.685>the <00:10:12.885>subsequent <00:10:13.084>uh,

277
00:10:13.825 --> 00:10:15.785
<00:10:13.825>then <00:10:13.965>we <00:10:14.105>wanna <00:10:14.245>determine <00:10:14.385>the <00:10:14.525>size <00:10:14.665>of <00:10:14.805>each <00:10:14.945>one <00:10:15.085>of <00:10:15.225>those

278
00:10:15.845 --> 00:10:16.905
<00:10:15.845>and <00:10:16.035>then <00:10:16.226>we <00:10:16.417>return <00:10:16.608>the <00:10:16.799>maximum.

279
00:10:17.405 --> 00:10:18.825
<00:10:17.405>So <00:10:17.564>in <00:10:17.724>now <00:10:17.884>how <00:10:18.044>to <00:10:18.203>do <00:10:18.363>the <00:10:18.523>last <00:10:18.683>step?

280
00:10:18.845 --> 00:10:20.425
<00:10:18.845>We <00:10:19.078>probably <00:10:19.311>call <00:10:19.545>us <00:10:19.778>the <00:10:20.011>ranges <00:10:20.245>max.

281
00:10:20.765 --> 00:10:21.865
<00:10:20.765>How <00:10:20.930>do <00:10:21.095>we <00:10:21.260>do <00:10:21.425>the <00:10:21.590>other <00:10:21.755>ones?

282
00:10:22.735 --> 00:10:25.625
<00:10:22.735>Well, <00:10:22.968>we <00:10:23.201>use <00:10:23.435>chunk <00:10:23.668>by, <00:10:23.901>so <00:10:24.135>chunk

283
00:10:25.685 --> 00:10:27.825
<00:10:25.685>by <00:10:25.859>is <00:10:26.035>a <00:10:26.209>bit <00:10:26.385>weird, <00:10:26.560>but <00:10:26.734>it's <00:10:26.910>really <00:10:27.084>powerful.

284
00:10:28.005 --> 00:10:30.345
<00:10:28.005>So <00:10:28.180>chunk <00:10:28.355>by <00:10:28.530>takes <00:10:28.705>a <00:10:28.880>range <00:10:29.055>and <00:10:29.230>a <00:10:29.405>predicate

285
00:10:30.565 --> 00:10:33.145
<00:10:30.565>and <00:10:30.740>it <00:10:30.915>essentially <00:10:31.090>splits <00:10:31.265>the <00:10:31.440>range <00:10:31.615>at <00:10:31.790>the <00:10:31.965>borders

286
00:10:33.145 --> 00:10:34.305
<00:10:33.145>where <00:10:33.406>the <00:10:33.666>predicate <00:10:33.928>returns <00:10:34.189>falls.

287
00:10:34.845 --> 00:10:37.145
<00:10:34.845>So <00:10:35.000>what <00:10:35.156>we <00:10:35.311>are <00:10:35.467>doing <00:10:35.622>is <00:10:35.778>we <00:10:35.933>are <00:10:36.089>going <00:10:36.245>over

288
00:10:37.145 --> 00:10:38.225
<00:10:37.145>them <00:10:37.339>one <00:10:37.533>pair <00:10:37.728>at <00:10:37.922>a <00:10:38.117>time.

289
00:10:38.365 --> 00:10:41.305
<00:10:38.365>So <00:10:38.505>like <00:10:38.645>pairs <00:10:38.785>after <00:10:38.925>each <00:10:39.065>other <00:10:39.205>and <00:10:39.345>passing <00:10:39.485>them <00:10:39.625>to <00:10:39.765>less.

290
00:10:41.685 --> 00:10:44.145
<00:10:41.685>And <00:10:41.801>as <00:10:41.918>long <00:10:42.035>as <00:10:42.151>the <00:10:42.268>first <00:10:42.385>one <00:10:42.501>is <00:10:42.618>less <00:10:42.734>than <00:10:42.851>the <00:10:42.968>second <00:10:43.084>one,

291
00:10:44.145 --> 00:10:45.465
<00:10:44.145>we <00:10:44.382>accumulate <00:10:44.620>them <00:10:44.857>in <00:10:45.095>one <00:10:45.333>chunk.

292
00:10:45.885 --> 00:10:48.785
<00:10:45.885>And <00:10:46.025>when <00:10:46.165>we <00:10:46.305>reach <00:10:46.444>three <00:10:46.585>two, <00:10:46.725>it's <00:10:46.865>no <00:10:47.005>longer <00:10:47.145>the <00:10:47.285>case.

293
00:10:48.785 --> 00:10:50.265
<00:10:48.785>So <00:10:48.951>we <00:10:49.117>split <00:10:49.284>it <00:10:49.451>and <00:10:49.617>start <00:10:49.784>a <00:10:49.950>new <00:10:50.117>chunk.

294
00:10:50.725 --> 00:10:53.105
<00:10:50.725>And <00:10:50.880>again, <00:10:51.036>this <00:10:51.191>is <00:10:51.347>lazily, <00:10:51.502>like <00:10:51.658>this <00:10:51.813>doesn't <00:10:51.969>do <00:10:52.125>anything.

295
00:10:53.255 --> 00:10:55.465
<00:10:53.255>Only <00:10:53.410>as <00:10:53.566>we <00:10:53.721>iterate <00:10:53.877>over <00:10:54.032>it <00:10:54.188>in <00:10:54.343>the <00:10:54.499>final <00:10:54.655>mix

296
00:10:55.605 --> 00:10:57.865
<00:10:55.605>to <00:10:55.838>lazily <00:10:56.071>compute <00:10:56.305>the <00:10:56.538>chunk <00:10:56.771>on <00:10:57.005>demand

297
00:10:58.005 --> 00:10:59.185
<00:10:58.005>by <00:10:58.270>returning <00:10:58.536>a <00:10:58.801>sub <00:10:59.067>range,

298
00:10:59.185 --> 00:11:01.385
<00:10:59.185>like <00:10:59.359>it <00:10:59.535>doesn't <00:10:59.709>eagerly <00:10:59.885>allocate <00:11:00.060>them <00:11:00.234>in <00:11:00.410>a <00:11:00.584>container

299
00:11:01.385 --> 00:11:04.305
<00:11:01.385>somewhere, <00:11:01.560>it <00:11:01.735>simply <00:11:01.910>marks <00:11:02.085>the <00:11:02.260>boundaries <00:11:02.435>of <00:11:02.610>the <00:11:02.785>chunks.

300
00:11:05.005 --> 00:11:06.585
<00:11:05.005>And <00:11:05.180>then <00:11:05.355>we <00:11:05.530>want <00:11:05.705>the <00:11:05.880>size <00:11:06.055>of <00:11:06.230>each <00:11:06.405>chunk.

301
00:11:06.685 --> 00:11:07.705
<00:11:06.685>So <00:11:06.914>we <00:11:07.144>call <00:11:07.373>it <00:11:07.603>transform.

302
00:11:07.845 --> 00:11:10.345
<00:11:07.845>So <00:11:08.000>transform <00:11:08.156>the <00:11:08.311>function <00:11:08.467>is <00:11:08.622>invoked <00:11:08.778>with <00:11:08.933>a <00:11:09.089>sub <00:11:09.245>range

303
00:11:10.445 --> 00:11:11.465
<00:11:10.445>and <00:11:10.628>we <00:11:10.812>wanna <00:11:10.995>get <00:11:11.179>that <00:11:11.363>size

304
00:11:11.685 --> 00:11:13.185
<00:11:11.685>and <00:11:11.853>then <00:11:12.022>we've <00:11:12.191>got <00:11:12.359>the <00:11:12.528>list <00:11:12.697>of <00:11:12.866>the <00:11:13.035>size

305
00:11:13.185 --> 00:11:15.625
<00:11:13.185>of <00:11:13.324>the <00:11:13.464>sub <00:11:13.604>sub <00:11:13.744>ranges <00:11:13.885>and <00:11:14.025>we <00:11:14.165>just <00:11:14.305>want <00:11:14.444>the <00:11:14.584>maximum.

306
00:11:15.925 --> 00:11:17.985
<00:11:15.925>And <00:11:16.080>so <00:11:16.236>we <00:11:16.391>call <00:11:16.547>that <00:11:16.702>and <00:11:16.858>this <00:11:17.013>computes <00:11:17.169>the <00:11:17.324>problem.

307
00:11:18.725 --> 00:11:21.905
<00:11:18.725>And <00:11:18.865>again, <00:11:19.005>this <00:11:19.145>is <00:11:19.285>like <00:11:19.425>once <00:11:19.565>you <00:11:19.705>know <00:11:19.845>all <00:11:19.985>the <00:11:20.125>tricks

308
00:11:21.905 --> 00:11:23.625
<00:11:21.905>and <00:11:22.079>all <00:11:22.255>the <00:11:22.430>views, <00:11:22.605>this <00:11:22.780>is <00:11:22.954>a <00:11:23.130>very <00:11:23.305>straightforward

309
00:11:23.685 --> 00:11:24.745
<00:11:23.685>way <00:11:23.923>to <00:11:24.161>solve <00:11:24.400>this <00:11:24.639>problem.

310
00:11:24.965 --> 00:11:26.385
<00:11:24.965>You <00:11:25.178>don't <00:11:25.391>have <00:11:25.604>to <00:11:25.817>deal <00:11:26.030>with, <00:11:26.242>okay,

311
00:11:26.385 --> 00:11:27.825
<00:11:26.385>this <00:11:26.644>is <00:11:26.903>the <00:11:27.162>current <00:11:27.421>chunk <00:11:27.681>boundary

312
00:11:27.925 --> 00:11:29.945
<00:11:27.925>and <00:11:28.099>can <00:11:28.275>I <00:11:28.449>add <00:11:28.625>this <00:11:28.800>new <00:11:28.974>element <00:11:29.150>in <00:11:29.324>there?

313
00:11:30.005 --> 00:11:32.145
<00:11:30.005>And <00:11:30.160>okay, <00:11:30.316>I <00:11:30.471>can't. <00:11:30.627>So <00:11:30.782>now <00:11:30.938>the <00:11:31.093>chunk <00:11:31.249>is <00:11:31.405>done.

314
00:11:32.185 --> 00:11:34.465
<00:11:32.185>I <00:11:32.340>have <00:11:32.496>to <00:11:32.651>remember <00:11:32.807>the <00:11:32.962>maximum, <00:11:33.118>like <00:11:33.273>it's <00:11:33.429>a <00:11:33.584>lot

315
00:11:34.465 --> 00:11:36.345
<00:11:34.465>of <00:11:34.698>manual <00:11:34.931>straight <00:11:35.165>state <00:11:35.398>wrangling <00:11:35.631>if <00:11:35.865>you

316
00:11:36.345 --> 00:11:37.425
<00:11:36.345>wanna <00:11:36.588>do <00:11:36.831>it <00:11:37.074>in <00:11:37.317>parallelly.

317
00:11:37.565 --> 00:11:39.145
<00:11:37.565>And <00:11:37.705>this <00:11:37.845>is <00:11:37.985>a <00:11:38.125>much <00:11:38.265>more <00:11:38.405>elegant <00:11:38.545>way <00:11:38.685>to <00:11:38.825>do <00:11:38.965>it

318
00:11:43.285 --> 00:11:44.945
<00:11:43.285>for <00:11:43.635>um, <00:11:43.985>a <00:11:44.334>similar <00:11:44.685>problem.

319
00:11:45.285 --> 00:11:47.985
<00:11:45.285>Um, <00:11:45.425>but <00:11:45.564>it's <00:11:45.704>clunky <00:11:45.844>if <00:11:45.985>you <00:11:46.125>wanna <00:11:46.265>do <00:11:46.405>it <00:11:46.545>by <00:11:46.685>hand,

320
00:11:47.985 --> 00:11:49.305
<00:11:47.985>but <00:11:48.222>very <00:11:48.460>elegant <00:11:48.697>as <00:11:48.935>this <00:11:49.173>one.

321
00:11:49.445 --> 00:11:52.305
<00:11:49.445>So <00:11:49.561>you <00:11:49.678>get <00:11:49.795>a <00:11:49.911>string <00:11:50.028>and <00:11:50.145>you <00:11:50.261>want <00:11:50.378>to <00:11:50.495>reverse <00:11:50.611>all <00:11:50.728>the <00:11:50.845>words

322
00:11:52.885 --> 00:11:54.605
<00:11:52.885>but <00:11:53.165>not <00:11:53.444>uh, <00:11:53.725>within <00:11:54.005>the <00:11:54.285>string.

323
00:11:55.145 --> 00:11:57.605
<00:11:55.145>So <00:11:55.272>if <00:11:55.399>our <00:11:55.526>string <00:11:55.654>is <00:11:55.781>hello <00:11:55.908>world, <00:11:56.035>the <00:11:56.163>output <00:11:56.290>would <00:11:56.417>be <00:11:56.545>uh,

324
00:11:57.605 --> 00:11:59.525
<00:11:57.605>this <00:11:57.838>which <00:11:58.071>has <00:11:58.305>all <00:11:58.538>the <00:11:58.771>worlds <00:11:59.005>flipped

325
00:11:59.745 --> 00:12:01.285
<00:11:59.745>but <00:12:00.022>kept <00:12:00.299>in <00:12:00.576>the <00:12:00.853>same <00:12:01.131>order.

326
00:12:03.785 --> 00:12:05.165
<00:12:03.785>So <00:12:04.033>here <00:12:04.281>the <00:12:04.530>composition <00:12:04.778>is <00:12:05.026>again,

327
00:12:05.165 --> 00:12:06.405
<00:12:05.165>we <00:12:05.351>wanna <00:12:05.536>split <00:12:05.723>the <00:12:05.909>string <00:12:06.095>into <00:12:06.281>words.

328
00:12:06.635 --> 00:12:07.925
<00:12:06.635>Then <00:12:06.867>we <00:12:07.099>wanna <00:12:07.331>reverse <00:12:07.563>each <00:12:07.795>chunk

329
00:12:08.145 --> 00:12:09.925
<00:12:08.145>and <00:12:08.300>then <00:12:08.456>we <00:12:08.611>wanna <00:12:08.767>put <00:12:08.922>all <00:12:09.078>the <00:12:09.233>chunks <00:12:09.389>back <00:12:09.545>together.

330
00:12:12.145 --> 00:12:13.405
<00:12:12.145>And <00:12:12.371>we <00:12:12.598>again <00:12:12.825>use <00:12:13.052>chunk <00:12:13.279>by.

331
00:12:13.505 --> 00:12:15.845
<00:12:13.505>So <00:12:13.645>we <00:12:13.785>started <00:12:13.925>with <00:12:14.064>our <00:12:14.205>string <00:12:14.345>and <00:12:14.485>we <00:12:14.625>say <00:12:14.765>chunk <00:12:14.905>it.

332
00:12:15.985 --> 00:12:18.845
<00:12:15.985>And <00:12:16.140>this <00:12:16.296>time <00:12:16.451>the <00:12:16.607>chunking <00:12:16.762>predicate <00:12:16.918>is <00:12:17.073>if <00:12:17.229>the <00:12:17.385>alphas

333
00:12:18.845 --> 00:12:19.845
<00:12:18.845>of <00:12:19.145>the <00:12:19.445>left <00:12:19.745>character

334
00:12:19.845 --> 00:12:21.885
<00:12:19.845>and <00:12:20.045>the <00:12:20.245>alphas <00:12:20.445>of <00:12:20.645>the <00:12:20.845>right <00:12:21.045>character <00:12:21.245>differs,

335
00:12:21.995 --> 00:12:23.765
<00:12:21.995>this <00:12:22.275>is <00:12:22.555>a <00:12:22.835>chunk <00:12:23.115>boundary, <00:12:23.395>right?

336
00:12:23.945 --> 00:12:25.965
<00:12:23.945>And <00:12:24.145>this <00:12:24.345>neatly <00:12:24.545>splits <00:12:24.745>the <00:12:24.945>chunks <00:12:25.145>into <00:12:25.345>chunks

337
00:12:25.965 --> 00:12:28.565
<00:12:25.965>that <00:12:26.105>if <00:12:26.245>all <00:12:26.385>letters <00:12:26.525>and <00:12:26.665>chunks <00:12:26.805>that <00:12:26.945>are, <00:12:27.085>uh, <00:12:27.225>non <00:12:27.365>letters,

338
00:12:29.315 --> 00:12:30.765
<00:12:29.315>then <00:12:29.532>we've <00:12:29.750>got <00:12:29.967>all <00:12:30.185>of <00:12:30.402>our <00:12:30.620>chunks.

339
00:12:31.145 --> 00:12:32.725
<00:12:31.145>And <00:12:31.345>if <00:12:31.545>the <00:12:31.745>chunk <00:12:31.944>begins <00:12:32.145>with <00:12:32.345>the <00:12:32.545>letter,

340
00:12:32.745 --> 00:12:34.045
<00:12:32.745>the <00:12:32.979>entire <00:12:33.213>chunk <00:12:33.447>consists <00:12:33.680>of <00:12:33.915>letters.

341
00:12:34.225 --> 00:12:36.245
<00:12:34.225>In <00:12:34.380>this <00:12:34.536>case <00:12:34.691>we <00:12:34.847>wanna <00:12:35.002>flip <00:12:35.158>it <00:12:35.313>by <00:12:35.469>calling <00:12:35.625>reverse.

342
00:12:36.865 --> 00:12:38.725
<00:12:36.865>Um, <00:12:37.065>otherwise <00:12:37.265>we <00:12:37.465>would <00:12:37.665>turn <00:12:37.865>the <00:12:38.065>chunk <00:12:38.265>unchanged.

343
00:12:39.025 --> 00:12:41.485
<00:12:39.025>And <00:12:39.165>now <00:12:39.305>we <00:12:39.444>are <00:12:39.584>essentially <00:12:39.725>done <00:12:39.865>it's <00:12:40.005>just <00:12:40.145>um, <00:12:40.285>a <00:12:40.425>list

344
00:12:41.485 --> 00:12:42.925
<00:12:41.485>of <00:12:41.701>strings <00:12:41.917>instead <00:12:42.133>of <00:12:42.348>a <00:12:42.564>single <00:12:42.781>string.

345
00:12:43.065 --> 00:12:44.325
<00:12:43.065>So <00:12:43.254>we <00:12:43.443>join <00:12:43.632>it <00:12:43.821>all <00:12:44.010>back <00:12:44.199>together

346
00:12:44.585 --> 00:12:46.445
<00:12:44.585>and <00:12:44.818>this <00:12:45.051>creates <00:12:45.285>a <00:12:45.518>lazy <00:12:45.751>range, <00:12:45.985>um,

347
00:12:46.875 --> 00:12:49.285
<00:12:46.875>over <00:12:47.050>all <00:12:47.225>the <00:12:47.400>individual <00:12:47.575>characters, <00:12:47.750>one <00:12:47.925>after <00:12:48.100>the <00:12:48.275>other.

348
00:12:49.705 --> 00:12:50.925
<00:12:49.705>And <00:12:49.979>up <00:12:50.254>until <00:12:50.528>this <00:12:50.803>point,

349
00:12:51.025 --> 00:12:53.365
<00:12:51.025>we <00:12:51.305>simply <00:12:51.584>declaratively <00:12:51.865>described <00:12:52.145>the <00:12:52.425>pipeline

350
00:12:53.425 --> 00:12:55.245
<00:12:53.425>and <00:12:53.625>only <00:12:53.824>when <00:12:54.025>we <00:12:54.224>calls <00:12:54.425>the <00:12:54.625>rangers <00:12:54.824>two,

351
00:12:55.425 --> 00:12:56.805
<00:12:55.425>we <00:12:55.735>actually <00:12:56.045>trigger <00:12:56.356>the <00:12:56.666>iteration.

352
00:12:56.825 --> 00:12:58.885
<00:12:56.825>We <00:12:57.058>actually <00:12:57.291>trigger, <00:12:57.525>uh, <00:12:57.758>the <00:12:57.991>actual <00:12:58.225>work.

353
00:12:58.985 --> 00:13:00.045
<00:12:58.985>We <00:12:59.223>will <00:12:59.462>iterate <00:12:59.700>over <00:12:59.939>them

354
00:13:00.265 --> 00:13:02.845
<00:13:00.265>and <00:13:00.392>add <00:13:00.519>them <00:13:00.646>one <00:13:00.774>end <00:13:00.901>at <00:13:01.028>a <00:13:01.155>time <00:13:01.283>to <00:13:01.410>the <00:13:01.537>final <00:13:01.665>string.

355
00:13:04.025 --> 00:13:07.645
<00:13:04.025>Now <00:13:04.180>one <00:13:04.336>slight <00:13:04.491>problem <00:13:04.647>with <00:13:04.802>this <00:13:04.958>problem, <00:13:05.113>uh, <00:13:05.269>program <00:13:05.425>is

356
00:13:07.645 --> 00:13:08.645
<00:13:07.645>that <00:13:07.944>it <00:13:08.245>doesn't <00:13:08.545>compile.

357
00:13:08.985 --> 00:13:11.485
<00:13:08.985>Um, <00:13:09.218>it's <00:13:09.451>because <00:13:09.685>we <00:13:09.918>in <00:13:10.151>the <00:13:10.385>predicate

358
00:13:11.485 --> 00:13:13.405
<00:13:11.485>for <00:13:11.660>transform <00:13:11.835>one <00:13:12.010>time <00:13:12.185>we <00:13:12.360>are <00:13:12.535>returning <00:13:12.710>the <00:13:12.885>chunk

359
00:13:13.465 --> 00:13:15.325
<00:13:13.465>and <00:13:13.640>one <00:13:13.815>time <00:13:13.990>we <00:13:14.165>are <00:13:14.340>returning <00:13:14.515>the <00:13:14.690>chunk <00:13:14.865>reversed.

360
00:13:16.785 --> 00:13:18.565
<00:13:16.785>And <00:13:17.018>these <00:13:17.251>are <00:13:17.485>two <00:13:17.718>different <00:13:17.951>types, <00:13:18.185>right?

361
00:13:18.585 --> 00:13:20.605
<00:13:18.585>One <00:13:18.725>is <00:13:18.865>a <00:13:19.005>chunk <00:13:19.145>and <00:13:19.285>one <00:13:19.425>is <00:13:19.565>a <00:13:19.705>laly <00:13:19.845>reversed <00:13:19.985>chunk.

362
00:13:20.785 --> 00:13:21.965
<00:13:20.785>And <00:13:20.936>we <00:13:21.088>could <00:13:21.240>solve <00:13:21.391>it <00:13:21.543>by, <00:13:21.695>for <00:13:21.847>example,

363
00:13:21.995 --> 00:13:24.285
<00:13:21.995>eagerly <00:13:22.195>converting <00:13:22.395>each <00:13:22.595>chunk <00:13:22.795>to <00:13:22.995>a <00:13:23.195>stood <00:13:23.395>string

364
00:13:24.385 --> 00:13:26.245
<00:13:24.385>and <00:13:24.560>then <00:13:24.735>returning <00:13:24.910>a <00:13:25.085>stood <00:13:25.260>string <00:13:25.435>in <00:13:25.610>either <00:13:25.785>case.

365
00:13:26.505 --> 00:13:29.605
<00:13:26.505>But <00:13:26.705>this <00:13:26.905>then <00:13:27.105>involves, <00:13:27.305>um, <00:13:27.505>unnecessary <00:13:27.705>um, <00:13:27.905>allocation.

366
00:13:29.945 --> 00:13:31.125
<00:13:29.945>And <00:13:30.476>unfortunately <00:13:31.007>as

367
00:13:31.125 --> 00:13:32.645
<00:13:31.125>of <00:13:31.320>now <00:13:31.515>the <00:13:31.711>c <00:13:31.906>plus <00:13:32.102>plus <00:13:32.297>standard <00:13:32.492>library

368
00:13:32.645 --> 00:13:33.765
<00:13:32.645>doesn't <00:13:32.981>have <00:13:33.317>the <00:13:33.653>solution.

369
00:13:34.105 --> 00:13:35.805
<00:13:34.105>Um, <00:13:34.385>but <00:13:34.665>I'm <00:13:34.945>planning <00:13:35.225>on <00:13:35.505>bringing

370
00:13:35.805 --> 00:13:36.965
<00:13:35.805>something <00:13:36.013>we <00:13:36.222>have <00:13:36.431>at <00:13:36.640>the <00:13:36.849>company.

371
00:13:37.025 --> 00:13:39.125
<00:13:37.025>So <00:13:37.152>we, <00:13:37.279>I <00:13:37.406>think <00:13:37.534>so <00:13:37.661>be <00:13:37.788>very <00:13:37.915>much <00:13:38.043>into <00:13:38.170>c <00:13:38.297>plus <00:13:38.425>plus.

372
00:13:39.385 --> 00:13:41.045
<00:13:39.385>Um, <00:13:39.560>we <00:13:39.735>use <00:13:39.910>it <00:13:40.085>to <00:13:40.260>do <00:13:40.435>a <00:13:40.610>PowerPoint <00:13:40.785>plugin.

373
00:13:41.045 --> 00:13:43.125
<00:13:41.045>We, <00:13:41.185>you <00:13:41.324>can <00:13:41.464>talk <00:13:41.604>about <00:13:41.745>it <00:13:41.885>later <00:13:42.025>if <00:13:42.165>you're <00:13:42.305>more <00:13:42.444>interesting,

374
00:13:43.125 --> 00:13:44.885
<00:13:43.125>but <00:13:43.325>it's <00:13:43.525>really <00:13:43.725>advanced <00:13:43.925>c <00:13:44.125>plus <00:13:44.325>plus <00:13:44.525>out.

375
00:13:44.945 --> 00:13:46.125
<00:13:44.945>We <00:13:45.210>do <00:13:45.476>everything <00:13:45.741>with <00:13:46.007>ranges

376
00:13:46.265 --> 00:13:47.365
<00:13:46.265>and <00:13:46.512>we've <00:13:46.760>got <00:13:47.007>a <00:13:47.255>utility

377
00:13:47.545 --> 00:13:49.405
<00:13:47.545>to <00:13:47.824>essentially, <00:13:48.104>um, <00:13:48.385>fix <00:13:48.665>this <00:13:48.944>problem.

378
00:13:49.465 --> 00:13:51.645
<00:13:49.465>So <00:13:49.640>it's <00:13:49.815>a <00:13:49.990>conditional <00:13:50.165>range, <00:13:50.340>it's <00:13:50.515>either <00:13:50.690>this <00:13:50.865>one

379
00:13:51.665 --> 00:13:54.085
<00:13:51.665>or <00:13:51.839>this <00:13:52.015>one <00:13:52.189>and <00:13:52.365>it <00:13:52.540>essentially <00:13:52.714>returns <00:13:52.890>the <00:13:53.064>variant

380
00:13:54.145 --> 00:13:56.285
<00:13:54.145>of <00:13:54.345>the <00:13:54.545>two <00:13:54.745>ranges <00:13:54.944>that <00:13:55.145>then <00:13:55.345>automatically <00:13:55.545>iterates

381
00:13:56.385 --> 00:13:58.325
<00:13:56.385>and <00:13:56.540>I <00:13:56.696>plan <00:13:56.851>on <00:13:57.007>bringing <00:13:57.162>that <00:13:57.318>to <00:13:57.473>the <00:13:57.629>standard <00:13:57.785>library,

382
00:13:58.505 --> 00:13:59.645
<00:13:58.505>uh, <00:13:58.710>for <00:13:58.915>c <00:13:59.120>plus <00:13:59.325>plus <00:13:59.531>29.

383
00:14:00.185 --> 00:14:02.485
<00:14:00.185>And <00:14:00.312>so <00:14:00.439>with <00:14:00.566>this <00:14:00.694>slide <00:14:00.821>we <00:14:00.948>got <00:14:01.075>of <00:14:01.203>the <00:14:01.330>way <00:14:01.457>this <00:14:01.584>compiles,

384
00:14:02.485 --> 00:14:03.645
<00:14:02.485>it's <00:14:02.746>an <00:14:03.007>example <00:14:03.268>that <00:14:03.529>works.

385
00:14:06.465 --> 00:14:10.245
<00:14:06.465>So <00:14:06.620>a <00:14:06.776>general <00:14:06.931>takeaways, <00:14:07.087>when <00:14:07.242>you <00:14:07.398>are <00:14:07.553>betting <00:14:07.709>algorithms, <00:14:07.865>try

386
00:14:10.245 --> 00:14:12.485
<00:14:10.245>to <00:14:10.478>identify <00:14:10.711>the <00:14:10.945>small <00:14:11.178>individual <00:14:11.411>building <00:14:11.645>blocks

387
00:14:12.625 --> 00:14:13.925
<00:14:12.625>for <00:14:12.917>solving <00:14:13.210>this <00:14:13.502>problem, <00:14:13.795>right?

388
00:14:14.105 --> 00:14:16.085
<00:14:14.105>If <00:14:14.245>you <00:14:14.385>wanna <00:14:14.525>do <00:14:14.665>some <00:14:14.805>kind <00:14:14.945>of <00:14:15.085>transformation <00:14:15.225>on <00:14:15.365>the <00:14:15.505>range,

389
00:14:16.085 --> 00:14:17.525
<00:14:16.085>just <00:14:16.344>transform <00:14:16.603>and <00:14:16.862>filter <00:14:17.121>if <00:14:17.381>you

390
00:14:17.525 --> 00:14:18.725
<00:14:17.525>wanna <00:14:17.885>combine <00:14:18.245>multiple <00:14:18.605>ranges.

391
00:14:18.725 --> 00:14:20.765
<00:14:18.725>And <00:14:18.925>so <00:14:19.125>one, <00:14:19.325>we've <00:14:19.525>seen <00:14:19.725>Cartesian <00:14:19.925>product, <00:14:20.125>um,

392
00:14:20.765 --> 00:14:23.405
<00:14:20.765>but <00:14:20.920>there's <00:14:21.076>also <00:14:21.231>zip <00:14:21.387>which <00:14:21.542>iterates <00:14:21.698>over <00:14:21.853>them <00:14:22.009>in <00:14:22.165>lockstep

393
00:14:23.545 --> 00:14:26.085
<00:14:23.545>or <00:14:23.700>concur, <00:14:23.856>which <00:14:24.011>iterator <00:14:24.167>over <00:14:24.322>them, <00:14:24.478>one <00:14:24.633>after <00:14:24.789>the <00:14:24.944>other.

394
00:14:26.665 --> 00:14:29.125
<00:14:26.665>Um, <00:14:26.805>if <00:14:26.944>you <00:14:27.084>wanna <00:14:27.224>split <00:14:27.365>ranges, <00:14:27.505>you <00:14:27.645>can <00:14:27.785>just <00:14:27.925>chunk <00:14:28.064>by

395
00:14:29.505 --> 00:14:31.245
<00:14:29.505>for <00:14:29.705>more <00:14:29.905>complex <00:14:30.105>stuff, <00:14:30.305>but <00:14:30.505>there's <00:14:30.705>also <00:14:30.905>split,

396
00:14:31.245 --> 00:14:33.805
<00:14:31.245>which <00:14:31.445>just <00:14:31.645>splits <00:14:31.845>it <00:14:32.045>on <00:14:32.245>a <00:14:32.445>specific <00:14:32.645>element.

397
00:14:34.305 --> 00:14:36.485
<00:14:34.305>Um, <00:14:34.444>and <00:14:34.584>then <00:14:34.724>to <00:14:34.864>join <00:14:35.005>them <00:14:35.145>back <00:14:35.285>together, <00:14:35.425>we've <00:14:35.564>got <00:14:35.704>join

398
00:14:36.485 --> 00:14:38.365
<00:14:36.485>and <00:14:36.718>join <00:14:36.951>with <00:14:37.185>which <00:14:37.418>inserts <00:14:37.651>a <00:14:37.885>separator.

399
00:14:38.825 --> 00:14:42.285
<00:14:38.825>And <00:14:38.952>then <00:14:39.079>we've <00:14:39.206>got <00:14:39.334>algorithms <00:14:39.461>like <00:14:39.588>Max <00:14:39.715>we <00:14:39.843>saw <00:14:39.970>finds <00:14:40.097>we <00:14:40.225>call.

400
00:14:42.585 --> 00:14:44.725
<00:14:42.585>So, <00:14:42.785>and <00:14:42.985>those <00:14:43.185>makes <00:14:43.385>it <00:14:43.585>really <00:14:43.785>um, <00:14:43.985>powerful.

401
00:14:45.225 --> 00:14:47.605
<00:14:45.225>And <00:14:45.380>if <00:14:45.536>you <00:14:45.691>do <00:14:45.847>this, <00:14:46.002>then <00:14:46.158>if <00:14:46.313>you <00:14:46.469>compose <00:14:46.625>algorithms,

402
00:14:47.605 --> 00:14:49.445
<00:14:47.605>you <00:14:47.838>minimize <00:14:48.071>the <00:14:48.305>use <00:14:48.538>of <00:14:48.771>follow-ups, <00:14:49.005>right?

403
00:14:49.545 --> 00:14:50.725
<00:14:49.545>We <00:14:49.757>solved <00:14:49.969>a <00:14:50.182>bunch <00:14:50.394>of <00:14:50.607>problems,

404
00:14:50.825 --> 00:14:52.125
<00:14:50.825>no <00:14:51.117>follow-ups <00:14:51.410>in <00:14:51.702>the <00:14:51.995>examples.

405
00:14:55.035 --> 00:14:57.375
<00:14:55.035>So <00:14:55.190>for <00:14:55.346>the <00:14:55.501>next <00:14:55.657>step, <00:14:55.812>let's <00:14:55.968>look <00:14:56.123>at <00:14:56.279>composing <00:14:56.435>functions.

406
00:15:01.915 --> 00:15:04.615
<00:15:01.915>So <00:15:02.055>this <00:15:02.194>is <00:15:02.334>some <00:15:02.474>code <00:15:02.615>we <00:15:02.755>are <00:15:02.895>given <00:15:03.035>a <00:15:03.175>user <00:15:03.314>id.

407
00:15:04.615 --> 00:15:06.935
<00:15:04.615>We <00:15:04.790>wanna <00:15:04.965>unsubscribe <00:15:05.140>the <00:15:05.315>user <00:15:05.490>from <00:15:05.665>the <00:15:05.840>mailing <00:15:06.015>list.

408
00:15:07.435 --> 00:15:09.455
<00:15:07.435>So <00:15:07.590>we <00:15:07.746>look <00:15:07.901>up <00:15:08.057>the <00:15:08.212>user, <00:15:08.368>we <00:15:08.523>get <00:15:08.679>us <00:15:08.834>email

409
00:15:09.455 --> 00:15:10.535
<00:15:09.455>and <00:15:09.698>then <00:15:09.941>we <00:15:10.184>unsubscribe <00:15:10.427>it.

410
00:15:10.795 --> 00:15:13.255
<00:15:10.795>And <00:15:10.950>in, <00:15:11.106>in <00:15:11.261>a <00:15:11.417>sense, <00:15:11.572>this <00:15:11.728>is <00:15:11.883>composition <00:15:12.039>of <00:15:12.194>functions.

411
00:15:13.595 --> 00:15:16.135
<00:15:13.595>So <00:15:13.702>we've <00:15:13.810>got <00:15:13.918>our <00:15:14.025>user <00:15:14.133>id, <00:15:14.241>we <00:15:14.348>turn <00:15:14.456>that <00:15:14.564>into <00:15:14.671>a <00:15:14.779>user, <00:15:14.887>we <00:15:14.995>turn

412
00:15:16.135 --> 00:15:17.895
<00:15:16.135>that <00:15:16.310>into <00:15:16.485>an <00:15:16.660>email <00:15:16.835>and <00:15:17.010>then <00:15:17.185>we <00:15:17.360>do <00:15:17.535>something.

413
00:15:18.475 --> 00:15:19.655
<00:15:18.475>And <00:15:18.740>this <00:15:19.006>is <00:15:19.271>very <00:15:19.537>straightforward,

414
00:15:20.155 --> 00:15:22.695
<00:15:20.155>but <00:15:20.355>what <00:15:20.555>if <00:15:20.755>the <00:15:20.954>intermediate <00:15:21.155>functions <00:15:21.355>can <00:15:21.555>fail

415
00:15:22.695 --> 00:15:23.735
<00:15:22.695>in <00:15:23.007>some <00:15:23.319>sense, <00:15:23.631>right?

416
00:15:24.195 --> 00:15:26.415
<00:15:24.195>For <00:15:24.322>example, <00:15:24.449>um, <00:15:24.576>to <00:15:24.704>look <00:15:24.831>up <00:15:24.958>the <00:15:25.085>user, <00:15:25.213>we <00:15:25.340>need <00:15:25.467>to <00:15:25.595>go

417
00:15:26.415 --> 00:15:28.055
<00:15:26.415>through <00:15:26.648>some <00:15:26.881>database <00:15:27.115>and <00:15:27.348>this <00:15:27.581>may <00:15:27.814>fail.

418
00:15:28.515 --> 00:15:29.815
<00:15:28.515>And <00:15:28.905>if <00:15:29.295>it <00:15:29.685>fails

419
00:15:29.815 --> 00:15:31.615
<00:15:29.815>by <00:15:29.970>throwing <00:15:30.126>an <00:15:30.281>exception, <00:15:30.437>then <00:15:30.592>we <00:15:30.748>need <00:15:30.903>to <00:15:31.059>handle <00:15:31.215>it.

420
00:15:31.755 --> 00:15:33.735
<00:15:31.755>And <00:15:31.895>let's <00:15:32.035>say <00:15:32.175>we <00:15:32.314>just <00:15:32.455>handle <00:15:32.595>it <00:15:32.735>by <00:15:32.875>logging <00:15:33.015>the <00:15:33.155>error

421
00:15:33.755 --> 00:15:36.335
<00:15:33.755>and <00:15:33.910>we're <00:15:34.066>trying <00:15:34.221>it <00:15:34.377>later <00:15:34.532>because <00:15:34.688>maybe <00:15:34.843>the <00:15:34.999>database <00:15:35.155>isn't,

422
00:15:36.445 --> 00:15:37.815
<00:15:36.445>it's <00:15:36.856>just <00:15:37.267>temporarily <00:15:37.678>available

423
00:15:38.755 --> 00:15:41.535
<00:15:38.755>and <00:15:38.910>this <00:15:39.066>isn't <00:15:39.221>a <00:15:39.377>very <00:15:39.532>imperative <00:15:39.688>way <00:15:39.843>of <00:15:39.999>composing <00:15:40.155>things

424
00:15:41.535 --> 00:15:44.055
<00:15:41.535>because <00:15:41.662>we've <00:15:41.789>got <00:15:41.916>this <00:15:42.044>uh, <00:15:42.171>state <00:15:42.298>in <00:15:42.425>there, <00:15:42.553>then <00:15:42.680>we <00:15:42.807>jump <00:15:42.935>out

425
00:15:44.055 --> 00:15:45.615
<00:15:44.055>of <00:15:44.210>there <00:15:44.366>to <00:15:44.521>some <00:15:44.677>other <00:15:44.832>code <00:15:44.988>to <00:15:45.143>handle <00:15:45.299>the <00:15:45.454>error.

426
00:15:46.035 --> 00:15:49.775
<00:15:46.035>Um, <00:15:46.175>and <00:15:46.314>we <00:15:46.454>can't <00:15:46.594>really <00:15:46.735>compose <00:15:46.875>it <00:15:47.015>directly <00:15:47.155>in <00:15:47.295>a <00:15:47.435>functional

427
00:15:49.775 --> 00:15:51.735
<00:15:49.775>sense <00:15:49.949>because <00:15:50.125>to <00:15:50.300>do <00:15:50.475>it <00:15:50.650>in <00:15:50.824>the <00:15:51.000>functional <00:15:51.175>sense,

428
00:15:51.735 --> 00:15:52.895
<00:15:51.735>we <00:15:52.083>need <00:15:52.431>values, <00:15:52.779>right?

429
00:15:53.295 --> 00:15:54.615
<00:15:53.295>Functional <00:15:53.691>composition <00:15:54.087>requires <00:15:54.483>values.

430
00:15:55.035 --> 00:15:56.855
<00:15:55.035>So <00:15:55.235>we <00:15:55.435>need <00:15:55.635>to <00:15:55.834>turn <00:15:56.035>this <00:15:56.235>error <00:15:56.435>into

431
00:15:56.855 --> 00:15:58.095
<00:15:56.855>value <00:15:57.041>so <00:15:57.227>we <00:15:57.413>can <00:15:57.599>work <00:15:57.785>with <00:15:57.971>it.

432
00:15:59.075 --> 00:16:01.215
<00:15:59.075>And <00:15:59.202>one <00:15:59.329>way <00:15:59.456>to <00:15:59.584>do <00:15:59.711>that <00:15:59.838>is <00:15:59.965>to <00:16:00.093>use <00:16:00.220>to <00:16:00.347>expect <00:16:00.475>it.

433
00:16:01.555 --> 00:16:04.575
<00:16:01.555>So <00:16:01.671>stood <00:16:01.788>expect <00:16:01.905>it, <00:16:02.021>um, <00:16:02.138>either <00:16:02.255>holds <00:16:02.371>the <00:16:02.488>T <00:16:02.604>in <00:16:02.721>which <00:16:02.838>case <00:16:02.954>we,

434
00:16:04.575 --> 00:16:06.935
<00:16:04.575>in <00:16:04.750>the <00:16:04.925>success <00:16:05.100>case <00:16:05.275>we <00:16:05.450>successfully <00:16:05.625>got <00:16:05.800>the <00:16:05.975>value

435
00:16:07.195 --> 00:16:08.935
<00:16:07.195>or <00:16:07.370>it <00:16:07.545>holds <00:16:07.720>an <00:16:07.895>E, <00:16:08.070>which <00:16:08.245>is <00:16:08.420>an <00:16:08.595>error.

436
00:16:09.875 --> 00:16:12.375
<00:16:09.875>And <00:16:10.015>so <00:16:10.155>let's <00:16:10.295>say <00:16:10.435>our <00:16:10.575>lookup <00:16:10.715>user <00:16:10.855>function <00:16:10.995>looks <00:16:11.135>like <00:16:11.275>this.

437
00:16:12.515 --> 00:16:14.495
<00:16:12.515>So <00:16:12.670>given <00:16:12.826>the <00:16:12.981>user <00:16:13.137>id, <00:16:13.292>we <00:16:13.448>either <00:16:13.603>get <00:16:13.759>the <00:16:13.915>user

438
00:16:14.675 --> 00:16:15.855
<00:16:14.675>or <00:16:14.887>we <00:16:15.099>get <00:16:15.312>the <00:16:15.524>database <00:16:15.737>error

439
00:16:17.315 --> 00:16:18.695
<00:16:17.315>and <00:16:17.492>then <00:16:17.669>we <00:16:17.847>can <00:16:18.024>write <00:16:18.202>code <00:16:18.379>like <00:16:18.557>this.

440
00:16:18.875 --> 00:16:21.775
<00:16:18.875>So <00:16:18.975>we <00:16:19.075>get <00:16:19.175>our <00:16:19.275>user. <00:16:19.375>Um, <00:16:19.475>if <00:16:19.575>you <00:16:19.675>have <00:16:19.775>a <00:16:19.875>user, <00:16:19.975>we <00:16:20.075>get <00:16:20.175>its <00:16:20.275>email

441
00:16:21.775 --> 00:16:24.455
<00:16:21.775>and <00:16:21.902>we <00:16:22.029>move <00:16:22.156>it, <00:16:22.284>otherwise <00:16:22.411>we <00:16:22.538>lock <00:16:22.665>the <00:16:22.793>error <00:16:22.920>in <00:16:23.047>virtual <00:16:23.175>later

442
00:16:25.755 --> 00:16:27.575
<00:16:25.755>and <00:16:25.955>now <00:16:26.155>the <00:16:26.355>composition <00:16:26.555>chain <00:16:26.755>is <00:16:26.955>still <00:16:27.155>there.

443
00:16:27.575 --> 00:16:30.375
<00:16:27.575>It's <00:16:27.691>just <00:16:27.808>a <00:16:27.925>bit <00:16:28.041>clunky <00:16:28.158>because <00:16:28.275>the <00:16:28.391>chain <00:16:28.508>is <00:16:28.625>given <00:16:28.741>a <00:16:28.858>user <00:16:28.975>id,

444
00:16:30.395 --> 00:16:32.935
<00:16:30.395>we <00:16:30.511>get <00:16:30.628>a <00:16:30.745>user <00:16:30.861>or <00:16:30.978>DB <00:16:31.095>error <00:16:31.211>and <00:16:31.328>then <00:16:31.444>we <00:16:31.561>get <00:16:31.678>an <00:16:31.795>email

445
00:16:32.955 --> 00:16:35.255
<00:16:32.955>or <00:16:33.188>DB <00:16:33.421>error <00:16:33.655>in <00:16:33.888>some <00:16:34.121>sense, <00:16:34.355>right?

446
00:16:35.255 --> 00:16:37.375
<00:16:35.255>So <00:16:35.430>this <00:16:35.605>isn't <00:16:35.780>really <00:16:35.955>the <00:16:36.130>functional <00:16:36.305>style <00:16:36.480>to <00:16:36.655>compost.

447
00:16:38.275 --> 00:16:39.815
<00:16:38.275>So <00:16:38.506>let's <00:16:38.737>look <00:16:38.968>at <00:16:39.199>the <00:16:39.430>first <00:16:39.661>step.

448
00:16:40.315 --> 00:16:42.575
<00:16:40.315>So <00:16:40.665>given <00:16:41.015>understood <00:16:41.365>expected <00:16:41.715>user

449
00:16:42.595 --> 00:16:45.375
<00:16:42.595>or <00:16:42.722>DB <00:16:42.849>error, <00:16:42.976>how <00:16:43.104>do <00:16:43.231>we <00:16:43.358>get <00:16:43.485>a <00:16:43.613>student <00:16:43.740>expected <00:16:43.867>for <00:16:43.995>email

450
00:16:45.395 --> 00:16:47.095
<00:16:45.395>or <00:16:46.095>DBO, <00:16:46.795>right?

451
00:16:47.095 --> 00:16:48.095
<00:16:47.095>And <00:16:47.245>you <00:16:47.395>can <00:16:47.545>write <00:16:47.695>code <00:16:47.845>like <00:16:47.995>this.

452
00:16:48.195 --> 00:16:50.375
<00:16:48.195>So <00:16:48.322>if <00:16:48.449>you <00:16:48.576>have <00:16:48.704>a <00:16:48.831>user, <00:16:48.958>we <00:16:49.085>turn <00:16:49.213>it <00:16:49.340>into <00:16:49.467>an <00:16:49.595>expected

453
00:16:50.555 --> 00:16:53.375
<00:16:50.555>of <00:16:50.694>its <00:16:50.834>email, <00:16:50.974>otherwise <00:16:51.114>we <00:16:51.255>would <00:16:51.395>turn <00:16:51.535>it <00:16:51.675>into <00:16:51.814>an <00:16:51.954>unexpected

454
00:16:53.405 --> 00:16:56.455
<00:16:53.405>that <00:16:53.638>contains <00:16:53.871>the, <00:16:54.105>and <00:16:54.338>this <00:16:54.571>function <00:16:54.805>is

455
00:16:56.455 --> 00:16:57.815
<00:16:56.455>so <00:16:56.659>common, <00:16:56.863>it's <00:16:57.067>in <00:16:57.271>the <00:16:57.475>standard <00:16:57.679>library.

456
00:16:58.195 --> 00:16:59.535
<00:16:58.195>Um, <00:16:58.597>it's <00:16:58.999>called <00:16:59.401>transform

457
00:16:59.535 --> 00:17:01.575
<00:16:59.535>because <00:16:59.768>in <00:17:00.001>some <00:17:00.235>sense <00:17:00.468>it's <00:17:00.701>transforms <00:17:00.935>the

458
00:17:01.775 --> 00:17:03.095
<00:17:01.775>expected <00:17:02.369>value, <00:17:02.963>right?

459
00:17:03.235 --> 00:17:05.655
<00:17:03.235>So <00:17:03.375>if <00:17:03.515>we <00:17:03.655>have <00:17:03.795>one, <00:17:03.935>we <00:17:04.075>pass <00:17:04.214>it <00:17:04.355>to <00:17:04.495>some <00:17:04.635>function

460
00:17:05.655 --> 00:17:08.055
<00:17:05.655>and <00:17:05.829>store <00:17:06.004>the <00:17:06.180>result, <00:17:06.355>otherwise <00:17:06.530>we <00:17:06.704>propagate <00:17:06.879>the <00:17:07.055>error

461
00:17:08.055 --> 00:17:11.545
<00:17:08.055>unchanged <00:17:08.182>and <00:17:08.309>that <00:17:08.436>way <00:17:08.564>we <00:17:08.691>can <00:17:08.818>just <00:17:08.945>say, <00:17:09.073>Hey, <00:17:09.200>given <00:17:09.327>our <00:17:09.455>user,

462
00:17:11.815 --> 00:17:13.465
<00:17:11.815>give <00:17:12.048>me <00:17:12.281>the <00:17:12.515>email <00:17:12.748>by <00:17:12.981>calling <00:17:13.215>transform

463
00:17:13.565 --> 00:17:16.105
<00:17:13.565>and <00:17:13.720>this <00:17:13.876>turns <00:17:14.031>an <00:17:14.187>expected <00:17:14.342>user <00:17:14.498>of <00:17:14.653>email, <00:17:14.809>a <00:17:14.965>user

464
00:17:16.105 --> 00:17:18.305
<00:17:16.105>of <00:17:16.305>error <00:17:16.505>into <00:17:16.704>an <00:17:16.905>expected <00:17:17.105>email <00:17:17.305>or <00:17:17.505>error.

465
00:17:20.205 --> 00:17:21.385
<00:17:20.204>And <00:17:20.417>now <00:17:20.629>we've <00:17:20.842>got <00:17:21.054>our <00:17:21.267>email.

466
00:17:21.525 --> 00:17:23.785
<00:17:21.525>How <00:17:21.758>do <00:17:21.991>we <00:17:22.225>conditionally <00:17:22.458>invoke <00:17:22.691>subscriber <00:17:22.925>list?

467
00:17:23.885 --> 00:17:26.785
<00:17:23.885>Remove <00:17:24.118>Well, <00:17:24.351>uh, <00:17:24.585>using <00:17:24.818>the <00:17:25.051>statement, <00:17:25.285>right?

468
00:17:26.785 --> 00:17:28.305
<00:17:26.785>So <00:17:26.956>if <00:17:27.127>you've <00:17:27.298>got <00:17:27.469>an <00:17:27.640>email, <00:17:27.811>we <00:17:27.982>remove <00:17:28.153>it.

469
00:17:28.765 --> 00:17:31.065
<00:17:28.765>But <00:17:28.920>in <00:17:29.076>some <00:17:29.231>sense <00:17:29.387>this <00:17:29.542>is <00:17:29.698>also <00:17:29.853>a <00:17:30.009>transformation, <00:17:30.165>right?

470
00:17:31.065 --> 00:17:32.425
<00:17:31.065>So <00:17:31.239>we <00:17:31.414>could <00:17:31.589>also <00:17:31.764>write <00:17:31.939>it <00:17:32.114>like <00:17:32.289>this.

471
00:17:32.765 --> 00:17:35.145
<00:17:32.765>So <00:17:32.920>given <00:17:33.076>our <00:17:33.231>email, <00:17:33.387>we <00:17:33.542>transform <00:17:33.698>it <00:17:33.853>into <00:17:34.009>some <00:17:34.165>sort

472
00:17:35.145 --> 00:17:37.385
<00:17:35.145>of <00:17:35.320>action <00:17:35.495>which <00:17:35.670>is <00:17:35.845>the <00:17:36.020>removal <00:17:36.195>of <00:17:36.370>the <00:17:36.545>subscriptions.

473
00:17:40.765 --> 00:17:43.705
<00:17:40.765>And <00:17:40.965>now <00:17:41.165>similarly <00:17:41.365>expected <00:17:41.565>also <00:17:41.765>has <00:17:41.965>transform <00:17:42.165>error,

474
00:17:43.705 --> 00:17:45.385
<00:17:43.705>which <00:17:43.938>applies <00:17:44.171>a <00:17:44.405>function <00:17:44.638>on <00:17:44.871>the <00:17:45.105>um,

475
00:17:45.385 --> 00:17:46.705
<00:17:45.385>error <00:17:45.682>channel <00:17:45.979>of <00:17:46.275>the <00:17:46.572>expected.

476
00:17:47.165 --> 00:17:48.625
<00:17:47.165>And <00:17:47.329>we <00:17:47.493>can <00:17:47.657>use <00:17:47.822>that <00:17:47.986>to <00:17:48.150>do <00:17:48.314>the <00:17:48.479>final

477
00:17:48.625 --> 00:17:49.645
<00:17:48.625>error <00:17:48.854>handling <00:17:49.084>at <00:17:49.313>the <00:17:49.543>end.

478
00:17:50.105 --> 00:17:52.685
<00:17:50.105>So <00:17:50.280>now <00:17:50.455>given <00:17:50.630>our <00:17:50.805>action, <00:17:50.980>we <00:17:51.155>transform <00:17:51.330>the <00:17:51.505>error.

479
00:17:52.905 --> 00:17:54.765
<00:17:52.905>So <00:17:53.105>if <00:17:53.305>the <00:17:53.504>entire <00:17:53.705>pipeline <00:17:53.905>contains <00:17:54.105>an <00:17:54.305>error,

480
00:17:54.905 --> 00:17:57.485
<00:17:54.905>we <00:17:55.060>handle <00:17:55.216>this <00:17:55.371>error <00:17:55.527>by <00:17:55.682>logging <00:17:55.838>it, <00:17:55.993>we <00:17:56.149>try <00:17:56.305>later

481
00:17:57.705 --> 00:17:59.365
<00:17:57.705>and <00:17:57.938>then <00:17:58.171>we <00:17:58.405>have <00:17:58.638>to <00:17:58.871>explicitly <00:17:59.105>say

482
00:17:59.365 --> 00:18:00.925
<00:17:59.365>that <00:17:59.565>we <00:17:59.765>discard <00:17:59.965>this <00:18:00.165>error <00:18:00.365>at <00:18:00.565>this <00:18:00.765>point

483
00:18:00.925 --> 00:18:02.685
<00:18:00.925>because <00:18:01.125>we <00:18:01.325>can't <00:18:01.524>just <00:18:01.725>return <00:18:01.925>void <00:18:02.125>from <00:18:02.325>there.

484
00:18:03.625 --> 00:18:05.605
<00:18:03.625>So <00:18:03.825>putting <00:18:04.025>this <00:18:04.225>all <00:18:04.425>together, <00:18:04.625>we've <00:18:04.825>ended <00:18:05.025>up

485
00:18:05.605 --> 00:18:06.725
<00:18:05.605>with <00:18:05.941>a <00:18:06.277>functional <00:18:06.612>pipeline.

486
00:18:07.065 --> 00:18:09.125
<00:18:07.065>So <00:18:07.220>we <00:18:07.376>look <00:18:07.531>up <00:18:07.687>the <00:18:07.842>user, <00:18:07.998>we <00:18:08.153>get <00:18:08.309>his <00:18:08.465>email,

487
00:18:09.345 --> 00:18:12.405
<00:18:09.345>we <00:18:09.472>remove <00:18:09.599>it <00:18:09.726>from <00:18:09.854>the <00:18:09.981>list, <00:18:10.108>and <00:18:10.235>this <00:18:10.363>is <00:18:10.490>the <00:18:10.617>error <00:18:10.745>handle.

488
00:18:12.825 --> 00:18:15.125
<00:18:12.825>And <00:18:13.105>this <00:18:13.385>is <00:18:13.665>a <00:18:13.945>declarative <00:18:14.225>thing,

489
00:18:15.125 --> 00:18:16.645
<00:18:15.125>like <00:18:15.353>we <00:18:15.581>don't <00:18:15.809>execute <00:18:16.037>them <00:18:16.264>in <00:18:16.493>order

490
00:18:16.645 --> 00:18:19.125
<00:18:16.645>because <00:18:16.820>we <00:18:16.995>are <00:18:17.170>either <00:18:17.345>executing <00:18:17.520>the <00:18:17.695>first <00:18:17.870>two <00:18:18.045>transforms

491
00:18:19.125 --> 00:18:20.245
<00:18:19.125>or <00:18:19.377>the <00:18:19.629>last <00:18:19.880>transform <00:18:20.132>error,

492
00:18:20.385 --> 00:18:22.325
<00:18:20.385>but <00:18:20.618>never <00:18:20.851>both <00:18:21.085>at <00:18:21.318>a <00:18:21.551>time, <00:18:21.785>right?

493
00:18:22.425 --> 00:18:23.925
<00:18:22.425>And <00:18:22.649>it's <00:18:22.875>also <00:18:23.100>at <00:18:23.325>a <00:18:23.550>glance <00:18:23.774>visible,

494
00:18:23.935 --> 00:18:25.125
<00:18:23.935>which <00:18:24.292>operations <00:18:24.649>can <00:18:25.006>fail.

495
00:18:25.645 --> 00:18:27.765
<00:18:25.645>Normally <00:18:25.878>only <00:18:26.111>the <00:18:26.345>lookup <00:18:26.578>user <00:18:26.811>ones <00:18:27.045>transform

496
00:18:27.765 --> 00:18:29.045
<00:18:27.765>and <00:18:28.149>transform <00:18:28.533>can <00:18:28.917>fail

497
00:18:29.065 --> 00:18:30.845
<00:18:29.065>and <00:18:29.298>transform <00:18:29.531>error <00:18:29.765>is <00:18:29.998>the <00:18:30.231>error <00:18:30.465>handling.

498
00:18:31.225 --> 00:18:34.765
<00:18:31.225>Um, <00:18:31.365>and <00:18:31.504>this <00:18:31.645>is <00:18:31.784>a <00:18:31.925>declarative <00:18:32.064>style <00:18:32.205>to <00:18:32.344>do <00:18:32.485>this <00:18:32.625>example.

499
00:18:35.745 --> 00:18:38.805
<00:18:35.745>Now <00:18:35.872>what <00:18:35.999>if <00:18:36.126>we <00:18:36.254>can't <00:18:36.381>just <00:18:36.508>get <00:18:36.635>the <00:18:36.763>email, <00:18:36.890>we <00:18:37.017>also <00:18:37.145>have

500
00:18:38.805 --> 00:18:40.645
<00:18:38.805>to <00:18:38.960>do <00:18:39.116>a <00:18:39.271>separate <00:18:39.427>DB <00:18:39.582>query <00:18:39.738>to <00:18:39.893>get <00:18:40.049>the <00:18:40.205>email

501
00:18:40.905 --> 00:18:42.045
<00:18:40.905>and <00:18:41.110>then <00:18:41.315>this <00:18:41.520>can <00:18:41.725>fail <00:18:41.931>again.

502
00:18:43.465 --> 00:18:45.845
<00:18:43.465>So <00:18:43.639>if <00:18:43.814>you <00:18:43.990>then <00:18:44.165>simply <00:18:44.340>use <00:18:44.514>transform, <00:18:44.689>we <00:18:44.865>enter

503
00:18:45.845 --> 00:18:48.405
<00:18:45.845>with <00:18:46.045>an <00:18:46.245>expected, <00:18:46.445>often <00:18:46.645>expected <00:18:46.845>with <00:18:47.045>our <00:18:47.245>email,

504
00:18:48.545 --> 00:18:50.205
<00:18:48.545>and <00:18:48.700>then <00:18:48.856>we've <00:18:49.011>got <00:18:49.167>two <00:18:49.322>levels <00:18:49.478>of <00:18:49.633>if <00:18:49.789>in <00:18:49.945>there.

505
00:18:50.425 --> 00:18:52.405
<00:18:50.425>The <00:18:50.552>first <00:18:50.679>one <00:18:50.806>is <00:18:50.934>two, <00:18:51.061>if <00:18:51.188>you <00:18:51.315>could <00:18:51.443>query <00:18:51.570>with <00:18:51.697>the <00:18:51.825>user.

506
00:18:52.665 --> 00:18:53.805
<00:18:52.665>And <00:18:52.836>then <00:18:53.007>the <00:18:53.178>second <00:18:53.349>one <00:18:53.520>is <00:18:53.691>two.

507
00:18:53.805 --> 00:18:56.805
<00:18:53.805>If <00:18:53.921>you <00:18:54.038>could <00:18:54.155>query <00:18:54.271>with <00:18:54.388>the <00:18:54.505>email, <00:18:54.621>and <00:18:54.738>this <00:18:54.855>is <00:18:54.971>a <00:18:55.088>bit <00:18:55.205>ugly

508
00:18:56.955 --> 00:18:59.045
<00:18:56.955>because <00:18:57.129>we <00:18:57.304>don't <00:18:57.480>really <00:18:57.655>care <00:18:57.830>about <00:18:58.004>either <00:18:58.179>failure <00:18:58.355>case,

509
00:18:59.045 --> 00:19:01.005
<00:18:59.045>we <00:18:59.278>wanna <00:18:59.511>like <00:18:59.745>unify <00:18:59.978>them <00:19:00.211>into <00:19:00.445>one.

510
00:19:01.705 --> 00:19:03.525
<00:19:01.705>So <00:19:01.879>you <00:19:02.054>can <00:19:02.230>write <00:19:02.405>a <00:19:02.580>function <00:19:02.754>to <00:19:02.929>unify <00:19:03.105>them.

511
00:19:03.865 --> 00:19:05.845
<00:19:03.865>Um, <00:19:04.065>similar <00:19:04.265>how <00:19:04.465>we <00:19:04.665>can <00:19:04.865>flatten <00:19:05.065>a <00:19:05.265>range

512
00:19:05.845 --> 00:19:07.805
<00:19:05.845>of <00:19:06.078>ranges <00:19:06.311>we <00:19:06.545>can <00:19:06.778>use <00:19:07.011>join, <00:19:07.245>um,

513
00:19:07.805 --> 00:19:10.285
<00:19:07.805>we <00:19:07.945>can <00:19:08.085>write <00:19:08.225>this <00:19:08.365>function <00:19:08.505>takes <00:19:08.645>an <00:19:08.785>expected <00:19:08.925>of <00:19:09.065>an <00:19:09.205>expected

514
00:19:10.625 --> 00:19:12.445
<00:19:10.625>and <00:19:10.825>flattens <00:19:11.025>it <00:19:11.225>out <00:19:11.425>into <00:19:11.625>a <00:19:11.825>single <00:19:12.025>expected

515
00:19:12.625 --> 00:19:14.005
<00:19:12.625>by <00:19:12.873>merging <00:19:13.121>the <00:19:13.370>two <00:19:13.618>error <00:19:13.867>cases.

516
00:19:14.865 --> 00:19:16.445
<00:19:14.865>But <00:19:15.040>this <00:19:15.215>is <00:19:15.390>a <00:19:15.565>bit <00:19:15.740>silly. <00:19:15.915>It's <00:19:16.090>much <00:19:16.265>better

517
00:19:16.445 --> 00:19:18.645
<00:19:16.445>to <00:19:16.620>avoid <00:19:16.794>the <00:19:16.970>expected <00:19:17.145>expected <00:19:17.320>in <00:19:17.495>the <00:19:17.669>first <00:19:17.845>case.

518
00:19:19.225 --> 00:19:21.645
<00:19:19.225>Um, <00:19:19.365>and <00:19:19.504>so <00:19:19.645>this, <00:19:19.784>there's <00:19:19.925>a <00:19:20.064>function <00:19:20.205>which <00:19:20.344>in <00:19:20.485>some <00:19:20.625>sense

519
00:19:21.645 --> 00:19:25.205
<00:19:21.645>automatically <00:19:21.820>joins, <00:19:21.995>uh, <00:19:22.170>and <00:19:22.345>it's <00:19:22.520>called <00:19:22.695>and <00:19:22.870>then <00:19:23.045>so

520
00:19:25.205 --> 00:19:26.685
<00:19:25.205>and <00:19:25.471>then <00:19:25.737>is <00:19:26.004>similar <00:19:26.270>to <00:19:26.537>transform,

521
00:19:26.865 --> 00:19:28.805
<00:19:26.865>but <00:19:27.098>we <00:19:27.331>are <00:19:27.565>transform <00:19:27.798>returns <00:19:28.031>a <00:19:28.265>function

522
00:19:28.805 --> 00:19:29.885
<00:19:28.805>that <00:19:29.129>returns <00:19:29.453>another <00:19:29.777>value.

523
00:19:30.235 --> 00:19:32.205
<00:19:30.235>This <00:19:30.435>is <00:19:30.635>a <00:19:30.834>function <00:19:31.034>that <00:19:31.235>returns <00:19:31.435>another <00:19:31.635>expected.

524
00:19:32.825 --> 00:19:34.605
<00:19:32.825>And <00:19:32.980>so <00:19:33.136>we <00:19:33.291>don't <00:19:33.447>need <00:19:33.602>to <00:19:33.758>web <00:19:33.913>the <00:19:34.069>return <00:19:34.225>type

525
00:19:34.605 --> 00:19:35.725
<00:19:34.605>of <00:19:34.857>the <00:19:35.109>function <00:19:35.360>into <00:19:35.612>expected

526
00:19:35.725 --> 00:19:37.845
<00:19:35.725>because <00:19:36.004>the <00:19:36.284>function <00:19:36.564>already <00:19:36.844>returns <00:19:37.125>unexpected.

527
00:19:39.065 --> 00:19:41.365
<00:19:39.065>And <00:19:39.220>so <00:19:39.376>if <00:19:39.531>we <00:19:39.687>use, <00:19:39.842>and <00:19:39.998>then <00:19:40.153>instead <00:19:40.309>of <00:19:40.465>transform,

528
00:19:41.585 --> 00:19:44.205
<00:19:41.585>we <00:19:41.712>just <00:19:41.839>get <00:19:41.966>the <00:19:42.094>query <00:19:42.221>email <00:19:42.348>and <00:19:42.475>we <00:19:42.603>flatten <00:19:42.730>it <00:19:42.857>all <00:19:42.985>out

529
00:19:44.345 --> 00:19:46.285
<00:19:44.345>and <00:19:44.500>then <00:19:44.656>we <00:19:44.811>still <00:19:44.967>have <00:19:45.122>an <00:19:45.278>expected <00:19:45.433>of <00:19:45.589>an <00:19:45.745>email

530
00:19:46.305 --> 00:19:48.765
<00:19:46.305>and <00:19:46.445>the <00:19:46.585>DB <00:19:46.725>error <00:19:46.865>and <00:19:47.005>not <00:19:47.145>the <00:19:47.285>expected <00:19:47.425>of <00:19:47.565>the <00:19:47.705>expected.

531
00:19:50.125 --> 00:19:53.065
<00:19:50.125>So <00:19:50.252>putting <00:19:50.379>this <00:19:50.506>all <00:19:50.634>together, <00:19:50.761>um, <00:19:50.888>we <00:19:51.015>end <00:19:51.143>up <00:19:51.270>with <00:19:51.397>this <00:19:51.525>code.

532
00:19:53.205 --> 00:19:55.105
<00:19:53.205>So <00:19:53.379>we <00:19:53.554>look <00:19:53.730>up <00:19:53.905>the <00:19:54.080>user, <00:19:54.254>this <00:19:54.429>can <00:19:54.605>fail,

533
00:19:55.525 --> 00:19:56.705
<00:19:55.525>we <00:19:55.790>then <00:19:56.056>query <00:19:56.321>the <00:19:56.587>email.

534
00:19:56.775 --> 00:19:58.585
<00:19:56.775>This <00:19:56.950>can <00:19:57.125>also <00:19:57.300>fail. <00:19:57.475>So <00:19:57.650>we <00:19:57.825>use <00:19:58.000>and <00:19:58.175>then

535
00:19:58.925 --> 00:20:00.465
<00:19:58.925>and <00:19:59.123>still <00:19:59.321>have <00:19:59.519>an <00:19:59.716>email <00:19:59.915>or <00:20:00.112>DB <00:20:00.311>error.

536
00:20:00.575 --> 00:20:03.025
<00:20:00.575>Then <00:20:00.750>we <00:20:00.925>execute <00:20:01.100>the <00:20:01.275>action. <00:20:01.450>This <00:20:01.625>one <00:20:01.800>can't <00:20:01.975>fail.

537
00:20:03.125 --> 00:20:04.745
<00:20:03.125>So <00:20:03.325>we <00:20:03.525>use <00:20:03.725>transform <00:20:03.925>and <00:20:04.125>then <00:20:04.325>we <00:20:04.525>still

538
00:20:04.745 --> 00:20:05.785
<00:20:04.745>have <00:20:04.979>the <00:20:05.213>same <00:20:05.447>error <00:20:05.681>handler.

539
00:20:06.285 --> 00:20:09.865
<00:20:06.285>And <00:20:06.440>that <00:20:06.596>way <00:20:06.751>it's <00:20:06.907>really <00:20:07.062>obvious <00:20:07.218>which <00:20:07.373>operations <00:20:07.529>can <00:20:07.685>fail.

540
00:20:10.095 --> 00:20:12.545
<00:20:10.095>Only <00:20:10.250>the <00:20:10.406>ones <00:20:10.561>with <00:20:10.717>and <00:20:10.872>then <00:20:11.028>can <00:20:11.183>introduce <00:20:11.339>additional <00:20:11.495>failure

541
00:20:12.545 --> 00:20:13.945
<00:20:12.545>States <00:20:12.797>not <00:20:13.049>the <00:20:13.301>one <00:20:13.553>with <00:20:13.804>transform

542
00:20:13.945 --> 00:20:15.985
<00:20:13.945>because <00:20:14.145>of <00:20:14.345>the <00:20:14.544>transform <00:20:14.745>one <00:20:14.945>were <00:20:15.145>to <00:20:15.345>fail,

543
00:20:16.045 --> 00:20:17.505
<00:20:16.045>it <00:20:16.373>would <00:20:16.702>return <00:20:17.030>another <00:20:17.359>expected

544
00:20:17.525 --> 00:20:19.865
<00:20:17.525>and <00:20:17.652>we <00:20:17.779>would <00:20:17.906>end <00:20:18.034>up <00:20:18.161>with <00:20:18.288>an <00:20:18.415>expected <00:20:18.543>expected <00:20:18.670>at <00:20:18.797>some <00:20:18.925>point

545
00:20:19.865 --> 00:20:22.025
<00:20:19.865>in <00:20:20.065>the <00:20:20.265>pipeline, <00:20:20.465>um, <00:20:20.665>which <00:20:20.865>would <00:20:21.065>cause <00:20:21.265>errors.

546
00:20:24.415 --> 00:20:27.835
<00:20:24.415>So <00:20:24.555>using <00:20:24.695>stood <00:20:24.835>expected, <00:20:24.975>we <00:20:25.115>can <00:20:25.254>model <00:20:25.395>fail <00:20:25.534>results <00:20:25.675>as <00:20:25.815>values

547
00:20:28.175 --> 00:20:30.235
<00:20:28.175>and <00:20:28.315>this <00:20:28.455>allows <00:20:28.595>us <00:20:28.735>to <00:20:28.875>compose <00:20:29.014>them <00:20:29.155>in <00:20:29.294>a <00:20:29.435>functional <00:20:29.575>way.

548
00:20:30.655 --> 00:20:33.355
<00:20:30.655>Um, <00:20:30.795>for <00:20:30.935>example, <00:20:31.075>we <00:20:31.215>can <00:20:31.355>use <00:20:31.495>transform <00:20:31.635>to <00:20:31.774>propose <00:20:31.915>as <00:20:32.055>values,

549
00:20:33.955 --> 00:20:36.635
<00:20:33.955>transform <00:20:34.110>error <00:20:34.266>to <00:20:34.421>process <00:20:34.577>the <00:20:34.732>error <00:20:34.888>and <00:20:35.043>we <00:20:35.199>can <00:20:35.355>use

550
00:20:36.655 --> 00:20:37.715
<00:20:36.655>and <00:20:36.893>then <00:20:37.132>to <00:20:37.370>chain <00:20:37.609>it

551
00:20:37.715 --> 00:20:39.395
<00:20:37.715>with <00:20:37.948>another <00:20:38.181>function <00:20:38.415>that <00:20:38.648>can <00:20:38.881>insert <00:20:39.115>fail.

552
00:20:40.415 --> 00:20:42.435
<00:20:40.415>And <00:20:40.615>I'm <00:20:40.815>not <00:20:41.014>saying <00:20:41.215>this <00:20:41.415>is <00:20:41.615>necessarily <00:20:41.815>superior

553
00:20:42.455 --> 00:20:44.795
<00:20:42.455>to <00:20:42.610>exceptions <00:20:42.766>in <00:20:42.921>all <00:20:43.077>cases <00:20:43.232>it <00:20:43.388>just <00:20:43.543>has <00:20:43.699>its <00:20:43.855>benefits.

554
00:20:45.095 --> 00:20:47.925
<00:20:45.095>Um, <00:20:45.295>if <00:20:45.495>the <00:20:45.695>error <00:20:45.895>cases <00:20:46.095>are <00:20:46.295>often, <00:20:46.495>uh,

555
00:20:47.995 --> 00:20:49.965
<00:20:47.995>then <00:20:48.344>exceptions <00:20:48.695>have <00:20:49.044>some <00:20:49.395>overhead

556
00:20:49.965 --> 00:20:51.005
<00:20:49.965>which <00:20:50.199>this <00:20:50.433>one <00:20:50.667>doesn't <00:20:50.901>have.

557
00:20:51.145 --> 00:20:52.125
<00:20:51.145>But <00:20:51.365>if <00:20:51.586>errors <00:20:51.806>are <00:20:52.027>aware,

558
00:20:52.125 --> 00:20:53.365
<00:20:52.125>then <00:20:52.404>exceptions <00:20:52.683>are <00:20:52.962>probably <00:20:53.241>better.

559
00:20:53.865 --> 00:20:55.045
<00:20:53.865>But <00:20:54.927>crucially,

560
00:20:55.045 --> 00:20:57.405
<00:20:55.045>this <00:20:55.200>one <00:20:55.356>makes <00:20:55.511>it <00:20:55.667>really <00:20:55.822>obvious <00:20:55.978>which <00:20:56.133>operations <00:20:56.289>can <00:20:56.445>fail

561
00:20:57.465 --> 00:20:59.365
<00:20:57.465>as <00:20:57.698>opposed <00:20:57.931>to <00:20:58.165>exceptions <00:20:58.398>where <00:20:58.631>everything <00:20:58.865>can

562
00:20:59.365 --> 00:21:00.525
<00:20:59.365>fail <00:20:59.626>because <00:20:59.887>everything <00:21:00.148>can <00:21:00.409>throw.

563
00:21:01.105 --> 00:21:03.245
<00:21:01.105>And <00:21:01.280>if <00:21:01.455>you <00:21:01.630>do <00:21:01.805>the <00:21:01.980>composition <00:21:02.155>using <00:21:02.330>transform <00:21:02.505>and,

564
00:21:03.245 --> 00:21:05.085
<00:21:03.245>and <00:21:03.524>then <00:21:03.804>then <00:21:04.084>we <00:21:04.364>minimize <00:21:04.645>it.

565
00:21:10.325 --> 00:21:12.665
<00:21:10.325>Now <00:21:10.558>finally, <00:21:10.791>let's <00:21:11.025>look <00:21:11.258>at <00:21:11.491>composing <00:21:11.725>io.

566
00:21:14.865 --> 00:21:17.205
<00:21:14.865>So <00:21:15.040>if <00:21:15.215>you're <00:21:15.390>having <00:21:15.565>a <00:21:15.740>pure <00:21:15.915>functional <00:21:16.090>programming <00:21:16.265>language,

567
00:21:17.265 --> 00:21:18.925
<00:21:17.265>all <00:21:17.615>functions <00:21:17.965>are <00:21:18.315>mathematical <00:21:18.665>functions.

568
00:21:19.195 --> 00:21:20.685
<00:21:19.195>That <00:21:19.386>means <00:21:19.578>they <00:21:19.769>don't <00:21:19.961>have <00:21:20.152>any <00:21:20.344>side <00:21:20.536>effects

569
00:21:20.685 --> 00:21:23.685
<00:21:20.685>during <00:21:20.840>computation <00:21:20.996>and <00:21:21.151>they <00:21:21.307>always <00:21:21.462>result <00:21:21.618>in <00:21:21.773>the <00:21:21.929>same <00:21:22.085>value

570
00:21:23.715 --> 00:21:25.285
<00:21:23.715>when <00:21:23.915>you <00:21:24.115>call <00:21:24.314>them <00:21:24.514>with <00:21:24.715>the <00:21:24.915>same <00:21:25.115>input.

571
00:21:26.545 --> 00:21:29.045
<00:21:26.545>And <00:21:26.685>this <00:21:26.825>means <00:21:26.965>that <00:21:27.105>you <00:21:27.245>do <00:21:27.385>not <00:21:27.525>have <00:21:27.665>any <00:21:27.805>global <00:21:27.945>state

572
00:21:29.785 --> 00:21:32.445
<00:21:29.785>and <00:21:29.940>you <00:21:30.096>also <00:21:30.251>cannot <00:21:30.407>write <00:21:30.562>any <00:21:30.718>functions <00:21:30.873>that <00:21:31.029>would <00:21:31.185>interact

573
00:21:32.445 --> 00:21:34.405
<00:21:32.445>with <00:21:32.620>the <00:21:32.794>outside <00:21:32.970>world <00:21:33.145>because <00:21:33.320>they <00:21:33.495>would <00:21:33.669>return <00:21:33.845>different

574
00:21:34.405 --> 00:21:36.005
<00:21:34.405>values <00:21:34.685>when <00:21:34.965>called <00:21:35.245>with <00:21:35.524>different <00:21:35.805>arguments.

575
00:21:36.905 --> 00:21:39.645
<00:21:36.905>So <00:21:37.060>this <00:21:37.216>raise <00:21:37.371>the <00:21:37.527>obvious <00:21:37.682>question <00:21:37.838>in <00:21:37.993>a <00:21:38.149>pure <00:21:38.305>function

576
00:21:39.645 --> 00:21:42.045
<00:21:39.645>program <00:21:39.845>language, <00:21:40.045>how <00:21:40.245>do <00:21:40.445>you <00:21:40.645>do <00:21:40.845>anything, <00:21:41.045>right?

577
00:21:42.145 --> 00:21:44.005
<00:21:42.145>If <00:21:42.345>you <00:21:42.545>can't <00:21:42.745>interact <00:21:42.945>with <00:21:43.145>the <00:21:43.345>outside <00:21:43.545>world,

578
00:21:44.105 --> 00:21:45.645
<00:21:44.105>how <00:21:44.382>do <00:21:44.659>you <00:21:44.936>do <00:21:45.213>anything, <00:21:45.491>right?

579
00:21:45.785 --> 00:21:47.285
<00:21:45.785>How <00:21:45.977>do <00:21:46.170>you <00:21:46.363>write <00:21:46.556>a <00:21:46.749>very <00:21:46.942>simple <00:21:47.135>function

580
00:21:47.285 --> 00:21:50.445
<00:21:47.285>that <00:21:47.425>reads <00:21:47.565>an <00:21:47.705>in <00:21:47.845>from <00:21:47.985>the <00:21:48.125>input <00:21:48.265>vulnerable <00:21:48.405>user <00:21:48.545>squares <00:21:48.685>it

581
00:21:50.445 --> 00:21:51.605
<00:21:50.445>and <00:21:50.653>writes <00:21:50.862>the <00:21:51.071>square <00:21:51.280>back <00:21:51.489>out?

582
00:21:53.275 --> 00:21:56.485
<00:21:53.275>Well <00:21:53.430>the <00:21:53.586>answer <00:21:53.741>is <00:21:53.897>you, <00:21:54.052>you <00:21:54.208>cheat <00:21:54.363>a <00:21:54.519>little <00:21:54.675>Instead

583
00:21:56.485 --> 00:21:58.245
<00:21:56.485>of <00:21:56.834>directly <00:21:57.185>manipulating <00:21:57.534>those <00:21:57.885>values,

584
00:21:58.625 --> 00:22:00.525
<00:21:58.625>you <00:21:58.975>manipulate <00:21:59.325>lists <00:21:59.675>of <00:22:00.025>actions.

585
00:22:01.025 --> 00:22:02.805
<00:22:01.025>So <00:22:01.225>instead <00:22:01.425>of <00:22:01.625>having <00:22:01.825>a <00:22:02.025>function <00:22:02.225>weed <00:22:02.425>in

586
00:22:02.805 --> 00:22:05.085
<00:22:02.805>that <00:22:02.960>returns <00:22:03.116>an <00:22:03.271>int <00:22:03.427>we <00:22:03.582>have <00:22:03.738>a <00:22:03.893>function <00:22:04.049>weed <00:22:04.205>in

587
00:22:05.085 --> 00:22:07.325
<00:22:05.085>that <00:22:05.285>returns <00:22:05.485>the <00:22:05.685>action <00:22:05.885>of <00:22:06.085>weeding <00:22:06.285>an <00:22:06.485>int.

588
00:22:07.785 --> 00:22:08.965
<00:22:07.785>And <00:22:07.997>this <00:22:08.209>is <00:22:08.422>a <00:22:08.634>pure <00:22:08.847>function

589
00:22:08.965 --> 00:22:10.965
<00:22:08.965>because <00:22:09.165>it <00:22:09.365>always <00:22:09.564>gives <00:22:09.764>you <00:22:09.965>the <00:22:10.165>same <00:22:10.365>action,

590
00:22:11.315 --> 00:22:13.125
<00:22:11.315>then <00:22:11.490>you <00:22:11.665>call <00:22:11.840>it <00:22:12.015>you <00:22:12.190>get <00:22:12.365>the <00:22:12.540>same <00:22:12.715>action,

591
00:22:13.145 --> 00:22:14.245
<00:22:13.145>the <00:22:13.343>one <00:22:13.541>that <00:22:13.739>reads <00:22:13.937>an <00:22:14.135>it.

592
00:22:14.745 --> 00:22:17.285
<00:22:14.745>And <00:22:14.885>similarly <00:22:15.024>we <00:22:15.165>have <00:22:15.304>a <00:22:15.445>function <00:22:15.584>white <00:22:15.725>end <00:22:15.864>which <00:22:16.004>takes <00:22:16.145>an

593
00:22:17.285 --> 00:22:19.685
<00:22:17.285>int <00:22:17.460>and <00:22:17.635>returns <00:22:17.810>the <00:22:17.985>action <00:22:18.160>of <00:22:18.335>writing <00:22:18.510>that <00:22:18.685>int.

594
00:22:19.945 --> 00:22:21.005
<00:22:19.945>And <00:22:20.183>this <00:22:20.422>is <00:22:20.660>also <00:22:20.899>pure

595
00:22:21.005 --> 00:22:22.525
<00:22:21.005>because <00:22:21.233>it <00:22:21.461>always <00:22:21.689>returns <00:22:21.917>the <00:22:22.145>same <00:22:22.373>action

596
00:22:22.525 --> 00:22:23.645
<00:22:22.525>when <00:22:22.726>called <00:22:22.928>with <00:22:23.129>the <00:22:23.331>same <00:22:23.533>end.

597
00:22:24.785 --> 00:22:26.405
<00:22:24.785>And <00:22:25.018>now <00:22:25.251>we <00:22:25.485>can't <00:22:25.718>directly <00:22:25.951>compose <00:22:26.185>them

598
00:22:26.405 --> 00:22:27.605
<00:22:26.405>because <00:22:26.675>when <00:22:26.945>you <00:22:27.215>call <00:22:27.485>ent,

599
00:22:27.605 --> 00:22:30.285
<00:22:27.605>you <00:22:27.712>don't <00:22:27.820>get <00:22:27.928>an <00:22:28.035>int <00:22:28.143>you <00:22:28.251>get <00:22:28.358>an <00:22:28.466>action <00:22:28.574>that <00:22:28.681>will <00:22:28.789>read <00:22:28.897>in <00:22:29.005>it,

600
00:22:31.345 --> 00:22:33.365
<00:22:31.345>but <00:22:31.520>we <00:22:31.695>can <00:22:31.870>give <00:22:32.045>it <00:22:32.220>the <00:22:32.395>similar <00:22:32.570>member <00:22:32.745>functions

601
00:22:33.365 --> 00:22:34.605
<00:22:33.365>as <00:22:33.644>we <00:22:33.923>gave <00:22:34.202>expected, <00:22:34.481>right?

602
00:22:34.605 --> 00:22:35.605
<00:22:34.605>We <00:22:34.785>could <00:22:34.965>say <00:22:35.145>we <00:22:35.325>transform <00:22:35.505>it.

603
00:22:36.505 --> 00:22:38.885
<00:22:36.505>So <00:22:36.680>we <00:22:36.855>call <00:22:37.030>wheat <00:22:37.205>and <00:22:37.380>we <00:22:37.555>give <00:22:37.730>it <00:22:37.905>transform.

604
00:22:38.885 --> 00:22:40.365
<00:22:38.885>And <00:22:39.218>transform <00:22:39.551>takes <00:22:39.884>a <00:22:40.217>function

605
00:22:40.545 --> 00:22:42.405
<00:22:40.545>and <00:22:40.745>it'll <00:22:40.945>at <00:22:41.145>some <00:22:41.345>point <00:22:41.545>apply <00:22:41.745>this <00:22:41.945>function

606
00:22:42.505 --> 00:22:43.645
<00:22:42.505>on <00:22:42.710>the <00:22:42.915>weed <00:22:43.120>that <00:22:43.325>was <00:22:43.531>in.

607
00:22:43.785 --> 00:22:45.645
<00:22:43.785>And <00:22:43.960>the <00:22:44.135>result <00:22:44.310>is <00:22:44.485>another <00:22:44.660>action <00:22:44.835>of <00:22:45.010>an <00:22:45.185>inch.

608
00:22:45.785 --> 00:22:47.965
<00:22:45.785>But <00:22:45.925>this <00:22:46.065>time <00:22:46.205>it's <00:22:46.345>the <00:22:46.485>square <00:22:46.625>and <00:22:46.765>not <00:22:46.905>just <00:22:47.045>the <00:22:47.185>value.

609
00:22:48.545 --> 00:22:51.565
<00:22:48.545>And <00:22:48.685>then <00:22:48.825>we <00:22:48.965>can <00:22:49.105>add <00:22:49.245>another <00:22:49.385>function, <00:22:49.525>uh, <00:22:49.665>white <00:22:49.805>end, <00:22:49.945>um,

610
00:22:51.615 --> 00:22:54.325
<00:22:51.615>which <00:22:51.790>combines <00:22:51.965>it <00:22:52.140>with <00:22:52.315>another <00:22:52.490>function, <00:22:52.665>we <00:22:52.840>invoke <00:22:53.015>it

611
00:22:54.325 --> 00:22:55.445
<00:22:54.325>and <00:22:54.577>this <00:22:54.829>returns <00:22:55.081>another <00:22:55.332>action.

612
00:22:55.445 --> 00:22:57.045
<00:22:55.445>So <00:22:55.620>we <00:22:55.794>use, <00:22:55.970>and <00:22:56.145>then <00:22:56.320>to <00:22:56.495>flatten <00:22:56.669>it <00:22:56.845>out

613
00:22:57.045 --> 00:22:58.805
<00:22:57.045>because <00:22:57.220>we <00:22:57.395>don't <00:22:57.570>want <00:22:57.745>an <00:22:57.920>action <00:22:58.095>of <00:22:58.270>an <00:22:58.445>action.

614
00:22:59.145 --> 00:23:01.245
<00:22:59.145>And <00:22:59.300>now <00:22:59.456>we've <00:22:59.611>got <00:22:59.767>our <00:22:59.922>pipeline, <00:23:00.078>we've <00:23:00.233>got <00:23:00.389>an <00:23:00.545>action

615
00:23:01.245 --> 00:23:03.245
<00:23:01.245>that <00:23:01.445>represents <00:23:01.645>the <00:23:01.844>act <00:23:02.044>of <00:23:02.245>reading <00:23:02.445>an <00:23:02.645>int,

616
00:23:03.605 --> 00:23:04.965
<00:23:03.605>squaring <00:23:03.849>it <00:23:04.094>and <00:23:04.339>writing <00:23:04.584>it <00:23:04.829>out.

617
00:23:06.025 --> 00:23:07.525
<00:23:06.025>And <00:23:06.217>then <00:23:06.410>we <00:23:06.603>can <00:23:06.796>write <00:23:06.989>our <00:23:07.182>main <00:23:07.375>function

618
00:23:07.525 --> 00:23:09.205
<00:23:07.525>where <00:23:07.700>we <00:23:07.875>get <00:23:08.050>our <00:23:08.225>action <00:23:08.400>and <00:23:08.575>we <00:23:08.750>call <00:23:08.925>one.

619
00:23:09.585 --> 00:23:11.365
<00:23:09.585>And <00:23:09.785>this <00:23:09.985>is <00:23:10.185>the <00:23:10.385>only <00:23:10.585>non <00:23:10.785>pure <00:23:10.985>thing.

620
00:23:11.435 --> 00:23:13.965
<00:23:11.435>This <00:23:11.635>will <00:23:11.835>actually <00:23:12.034>start <00:23:12.235>executing <00:23:12.435>our <00:23:12.635>code, <00:23:12.835>um,

621
00:23:14.195 --> 00:23:15.885
<00:23:14.195>perform <00:23:14.395>all <00:23:14.595>the <00:23:14.794>actions <00:23:14.995>and <00:23:15.195>do <00:23:15.395>the <00:23:15.595>thing.

622
00:23:16.545 --> 00:23:18.645
<00:23:16.545>And <00:23:16.700>now <00:23:16.856>if <00:23:17.011>you're <00:23:17.167>biting <00:23:17.322>in <00:23:17.478>a <00:23:17.633>pure <00:23:17.789>functional <00:23:17.945>programming

623
00:23:18.805 --> 00:23:20.765
<00:23:18.805>language, <00:23:18.980>you <00:23:19.155>just <00:23:19.330>pretend <00:23:19.505>that <00:23:19.680>your <00:23:19.855>entire <00:23:20.030>program <00:23:20.205>is

624
00:23:20.765 --> 00:23:22.045
<00:23:20.765>above <00:23:21.053>the <00:23:21.341>main <00:23:21.629>function, <00:23:21.917>right?

625
00:23:22.075 --> 00:23:24.245
<00:23:22.075>Then <00:23:22.275>just <00:23:22.475>dealing <00:23:22.675>with <00:23:22.875>actions. <00:23:23.075>Everything <00:23:23.275>is <00:23:23.475>pure.

626
00:23:24.345 --> 00:23:25.445
<00:23:24.345>You <00:23:24.675>never <00:23:25.004>do <00:23:25.335>anything.

627
00:23:25.665 --> 00:23:28.285
<00:23:25.665>And <00:23:25.805>then <00:23:25.945>after <00:23:26.085>the <00:23:26.225>hasker <00:23:26.365>program <00:23:26.504>is <00:23:26.645>done, <00:23:26.784>in <00:23:26.925>some <00:23:27.065>sense,

628
00:23:28.305 --> 00:23:29.925
<00:23:28.305>the <00:23:28.585>one <00:23:28.865>time <00:23:29.145>actually <00:23:29.425>execute <00:23:29.705>it,

629
00:23:30.105 --> 00:23:31.885
<00:23:30.105>do <00:23:30.260>all <00:23:30.416>the <00:23:30.571>side <00:23:30.727>effects <00:23:30.882>and <00:23:31.038>does <00:23:31.193>all <00:23:31.349>the <00:23:31.505>action.

630
00:23:33.625 --> 00:23:36.165
<00:23:33.625>Now <00:23:33.780>in <00:23:33.936>c <00:23:34.091>plus <00:23:34.247>plus <00:23:34.402>your <00:23:34.558>functions <00:23:34.713>don't <00:23:34.869>necessarily <00:23:35.025>need

631
00:23:36.165 --> 00:23:39.045
<00:23:36.165>to <00:23:36.340>be <00:23:36.514>pure, <00:23:36.690>but <00:23:36.865>it's <00:23:37.040>still <00:23:37.215>a <00:23:37.389>good <00:23:37.565>idea

632
00:23:39.045 --> 00:23:40.485
<00:23:39.045>to <00:23:39.369>separate <00:23:39.693>IO <00:23:40.017>from <00:23:40.341>computation.

633
00:23:40.745 --> 00:23:42.525
<00:23:40.745>Um, <00:23:40.945>this <00:23:41.145>allows <00:23:41.344>you <00:23:41.544>to <00:23:41.745>write <00:23:41.945>a <00:23:42.145>function

634
00:23:42.525 --> 00:23:44.325
<00:23:42.525>that <00:23:42.758>only <00:23:42.991>takes <00:23:43.225>some <00:23:43.458>input <00:23:43.691>processes, <00:23:43.925>it

635
00:23:44.345 --> 00:23:45.445
<00:23:44.345>and <00:23:44.543>doesn't <00:23:44.741>do <00:23:44.939>any <00:23:45.137>a <00:23:45.335>l.

636
00:23:45.705 --> 00:23:47.285
<00:23:45.705>And <00:23:45.905>so <00:23:46.105>it's <00:23:46.304>easier <00:23:46.504>to <00:23:46.705>test, <00:23:46.905>it's <00:23:47.105>easier

637
00:23:47.285 --> 00:23:48.645
<00:23:47.285>to <00:23:47.529>swipe <00:23:47.774>out <00:23:48.019>input <00:23:48.264>or <00:23:48.509>output.

638
00:23:50.105 --> 00:23:52.645
<00:23:50.105>And <00:23:50.260>for <00:23:50.416>this, <00:23:50.571>this <00:23:50.727>composing <00:23:50.882>action <00:23:51.038>scheme <00:23:51.193>can <00:23:51.349>still <00:23:51.505>be

639
00:23:52.645 --> 00:23:54.725
<00:23:52.645>useful, <00:23:52.925>like <00:23:53.205>first <00:23:53.485>declaratively <00:23:53.764>compose <00:23:54.045>your

640
00:23:55.185 --> 00:23:56.365
<00:23:55.185>and <00:23:55.450>then <00:23:55.716>execute <00:23:55.981>them <00:23:56.247>later.

641
00:23:57.635 --> 00:24:00.495
<00:23:57.635>And <00:23:57.751>c <00:23:57.868>plus <00:23:57.985>plus <00:23:58.101>26 <00:23:58.218>will <00:23:58.335>also <00:23:58.451>come <00:23:58.568>with <00:23:58.685>a <00:23:58.801>brand <00:23:58.918>new <00:23:59.035>framework

642
00:24:00.495 --> 00:24:03.575
<00:24:00.495>for <00:24:00.728>that, <00:24:00.961>um, <00:24:01.195>called <00:24:01.428>Send <00:24:01.661>US <00:24:01.895>receivers.

643
00:24:03.955 --> 00:24:06.175
<00:24:03.955>And <00:24:04.155>they <00:24:04.355>are <00:24:04.554>used <00:24:04.754>for <00:24:04.955>parallelism <00:24:05.155>and <00:24:05.355>concurrency.

644
00:24:06.475 --> 00:24:07.495
<00:24:06.475>So <00:24:06.704>we've <00:24:06.934>got <00:24:07.163>a <00:24:07.392>sender

645
00:24:07.555 --> 00:24:09.255
<00:24:07.555>and <00:24:07.788>in <00:24:08.021>some <00:24:08.255>sense <00:24:08.488>this <00:24:08.721>represents <00:24:08.955>a

646
00:24:09.255 --> 00:24:10.335
<00:24:09.255>value <00:24:09.417>at <00:24:09.579>some <00:24:09.741>point <00:24:09.903>in <00:24:10.065>the <00:24:10.227>future.

647
00:24:10.635 --> 00:24:12.175
<00:24:10.635>So <00:24:10.981>eventually <00:24:11.328>function <00:24:11.674>will <00:24:12.021>compute

648
00:24:12.235 --> 00:24:13.375
<00:24:12.235>and <00:24:12.440>it'll <00:24:12.645>give <00:24:12.850>you <00:24:13.055>some <00:24:13.261>value

649
00:24:13.795 --> 00:24:15.735
<00:24:13.795>and <00:24:13.995>then <00:24:14.195>you <00:24:14.395>can <00:24:14.595>combine <00:24:14.795>them <00:24:14.995>using <00:24:15.195>transform.

650
00:24:15.735 --> 00:24:17.855
<00:24:15.735>Unfortunately <00:24:15.968>the <00:24:16.201>transform <00:24:16.435>thing <00:24:16.668>is <00:24:16.901>called <00:24:17.135>then.

651
00:24:18.275 --> 00:24:20.815
<00:24:18.275>Um, <00:24:18.430>and <00:24:18.586>the, <00:24:18.741>and <00:24:18.897>then <00:24:19.052>function <00:24:19.208>is <00:24:19.363>called <00:24:19.519>let <00:24:19.675>value.

652
00:24:20.845 --> 00:24:23.695
<00:24:20.845>It's <00:24:21.020>a <00:24:21.195>bit <00:24:21.370>confusing, <00:24:21.545>but <00:24:21.720>essentially <00:24:21.895>you <00:24:22.070>can <00:24:22.245>declaratively

653
00:24:24.455 --> 00:24:27.175
<00:24:24.455>describe <00:24:24.629>your <00:24:24.804>concurrency <00:24:24.980>and <00:24:25.155>then <00:24:25.330>execute <00:24:25.504>them <00:24:25.679>in <00:24:25.855>parallel.

654
00:24:27.435 --> 00:24:29.895
<00:24:27.435>Um, <00:24:27.575>and <00:24:27.715>this <00:24:27.855>makes <00:24:27.995>it <00:24:28.135>very <00:24:28.274>easy <00:24:28.415>to <00:24:28.554>write <00:24:28.695>complex <00:24:28.835>code

655
00:24:29.895 --> 00:24:31.375
<00:24:29.895>that <00:24:30.561>es <00:24:31.227>stuff

656
00:24:31.475 --> 00:24:34.095
<00:24:31.475>by <00:24:31.708>just <00:24:31.941>declaratively <00:24:32.175>describing <00:24:32.408>your <00:24:32.641>data <00:24:32.875>pipeline

657
00:24:34.155 --> 00:24:36.055
<00:24:34.155>and <00:24:34.355>then <00:24:34.555>executing <00:24:34.754>them <00:24:34.955>on <00:24:35.155>some <00:24:35.355>fat <00:24:35.555>pull.

658
00:24:36.235 --> 00:24:38.855
<00:24:36.235>And <00:24:36.409>it'll <00:24:36.584>all <00:24:36.760>just <00:24:36.935>work <00:24:37.110>by <00:24:37.284>manipulating <00:24:37.459>these, <00:24:37.635>um,

659
00:24:39.325 --> 00:24:41.695
<00:24:39.325>lazy <00:24:39.558>values, <00:24:39.791>uh, <00:24:40.025>represented <00:24:40.258>in <00:24:40.491>the <00:24:40.725>future.

660
00:24:43.615 --> 00:24:46.355
<00:24:43.615>So <00:24:43.790>declaratively <00:24:43.965>build <00:24:44.140>your <00:24:44.315>plans <00:24:44.490>and <00:24:44.665>execute <00:24:44.840>them <00:24:45.015>later

661
00:24:46.575 --> 00:24:48.235
<00:24:46.575>and <00:24:46.925>separate <00:24:47.275>AO <00:24:47.625>from <00:24:47.975>computation

662
00:24:48.655 --> 00:24:50.595
<00:24:48.655>and <00:24:48.888>that <00:24:49.121>way <00:24:49.355>you <00:24:49.588>minimize <00:24:49.821>impure <00:24:50.055>functions.

663
00:24:53.325 --> 00:24:57.065
<00:24:53.325>Now <00:24:53.500>to <00:24:53.675>conclude <00:24:53.850>this <00:24:54.025>might <00:24:54.200>seem <00:24:54.375>a <00:24:54.550>little <00:24:54.725>repetitive.

664
00:24:58.085 --> 00:24:59.305
<00:24:58.085>Uh, <00:24:58.304>first <00:24:58.524>we <00:24:58.743>looked <00:24:58.963>at <00:24:59.183>ranges.

665
00:24:59.565 --> 00:25:01.105
<00:24:59.565>Ranges <00:24:59.842>contains <00:25:00.119>zero <00:25:00.396>or <00:25:00.673>more <00:25:00.951>values

666
00:25:01.445 --> 00:25:03.385
<00:25:01.445>and <00:25:01.620>we <00:25:01.794>can <00:25:01.970>transform <00:25:02.145>those <00:25:02.320>to <00:25:02.495>change <00:25:02.669>those <00:25:02.845>values.

667
00:25:03.805 --> 00:25:05.945
<00:25:03.805>Um, <00:25:03.945>we <00:25:04.085>could <00:25:04.225>write <00:25:04.365>like <00:25:04.505>there's <00:25:04.645>a <00:25:04.785>view <00:25:04.925>in <00:25:05.065>the <00:25:05.205>standard

668
00:25:05.945 --> 00:25:08.665
<00:25:05.945>library <00:25:06.100>at <00:25:06.256>some <00:25:06.411>point <00:25:06.567>in <00:25:06.722>the <00:25:06.878>future <00:25:07.033>called <00:25:07.189>transform <00:25:07.345>join.

669
00:25:08.695 --> 00:25:11.105
<00:25:08.695>This <00:25:08.835>will <00:25:08.975>change <00:25:09.115>those <00:25:09.254>values <00:25:09.395>and <00:25:09.534>join <00:25:09.675>them <00:25:09.814>all <00:25:09.955>in <00:25:10.095>one.

670
00:25:11.605 --> 00:25:13.585
<00:25:11.605>Um, <00:25:11.838>and <00:25:12.071>join <00:25:12.305>can <00:25:12.538>be <00:25:12.771>used <00:25:13.005>directly

671
00:25:13.585 --> 00:25:14.665
<00:25:13.585>to <00:25:13.828>flatten <00:25:14.071>those <00:25:14.314>nested <00:25:14.557>rangers.

672
00:25:15.925 --> 00:25:18.265
<00:25:15.925>Um, <00:25:16.100>we've <00:25:16.274>got <00:25:16.450>stood <00:25:16.625>expected, <00:25:16.800>which <00:25:16.975>contains <00:25:17.149>a <00:25:17.325>value

673
00:25:18.285 --> 00:25:20.265
<00:25:18.285>or <00:25:18.485>nothing <00:25:18.685>like <00:25:18.885>uh, <00:25:19.085>some <00:25:19.285>sort <00:25:19.485>of <00:25:19.685>error.

674
00:25:20.525 --> 00:25:22.865
<00:25:20.525>Um, <00:25:20.652>we <00:25:20.779>can <00:25:20.906>use <00:25:21.034>transform <00:25:21.161>to <00:25:21.288>change <00:25:21.415>the <00:25:21.543>value <00:25:21.670>we <00:25:21.797>can <00:25:21.925>use

675
00:25:22.885 --> 00:25:24.065
<00:25:22.885>and <00:25:23.097>then <00:25:23.309>to <00:25:23.522>change <00:25:23.734>the <00:25:23.947>value

676
00:25:24.165 --> 00:25:26.265
<00:25:24.165>by <00:25:24.340>adding <00:25:24.514>in <00:25:24.690>another <00:25:24.865>function <00:25:25.040>that <00:25:25.215>returns <00:25:25.389>an <00:25:25.565>error.

677
00:25:26.725 --> 00:25:28.305
<00:25:26.725>Um, <00:25:26.925>and <00:25:27.125>then <00:25:27.324>we <00:25:27.524>can <00:25:27.725>provide <00:25:27.925>a <00:25:28.125>function

678
00:25:28.305 --> 00:25:29.305
<00:25:28.305>that <00:25:28.530>joins <00:25:28.755>the <00:25:28.980>model <00:25:29.205>together.

679
00:25:30.285 --> 00:25:32.065
<00:25:30.285>And <00:25:30.460>then <00:25:30.635>we've <00:25:30.810>looked <00:25:30.985>at <00:25:31.160>this <00:25:31.335>IO <00:25:31.510>action <00:25:31.685>briefly.

680
00:25:32.215 --> 00:25:33.665
<00:25:32.215>This <00:25:32.432>contains <00:25:32.649>a <00:25:32.867>value <00:25:33.085>in <00:25:33.302>the <00:25:33.520>future

681
00:25:34.045 --> 00:25:36.065
<00:25:34.045>and <00:25:34.245>we <00:25:34.445>can <00:25:34.645>change <00:25:34.845>this <00:25:35.045>value <00:25:35.245>using <00:25:35.445>transform

682
00:25:36.065 --> 00:25:37.905
<00:25:36.065>and <00:25:36.240>we <00:25:36.415>can <00:25:36.590>change <00:25:36.765>another <00:25:36.940>function <00:25:37.115>in <00:25:37.290>the <00:25:37.465>using.

683
00:25:37.905 --> 00:25:39.945
<00:25:37.905>And <00:25:38.045>then, <00:25:38.185>and <00:25:38.325>we <00:25:38.465>could <00:25:38.605>also <00:25:38.745>write <00:25:38.885>a <00:25:39.024>function <00:25:39.165>called <00:25:39.305>join.

684
00:25:40.685 --> 00:25:43.585
<00:25:40.685>And <00:25:40.840>all <00:25:40.996>of <00:25:41.151>those <00:25:41.307>three <00:25:41.462>things <00:25:41.618>are <00:25:41.773>essentially <00:25:41.929>the <00:25:42.085>same.

685
00:25:43.775 --> 00:25:45.225
<00:25:43.775>This <00:25:44.036>is <00:25:44.297>because <00:25:44.558>they're <00:25:44.819>all <00:25:45.080>Monets.

686
00:25:47.095 --> 00:25:51.315
<00:25:47.095>Now <00:25:47.270>Monets <00:25:47.445>are <00:25:47.620>this <00:25:47.795>like <00:25:47.970>crazy <00:25:48.145>complex <00:25:48.320>functional <00:25:48.495>thing,

687
00:25:51.315 --> 00:25:53.195
<00:25:51.315>but <00:25:51.490>it's <00:25:51.665>like <00:25:51.840>in <00:25:52.015>super <00:25:52.190>systems <00:25:52.365>it's <00:25:52.540>really <00:25:52.715>simple.

688
00:25:53.195 --> 00:25:55.715
<00:25:53.195>It's <00:25:53.335>just <00:25:53.475>some <00:25:53.615>type <00:25:53.754>that <00:25:53.895>has <00:25:54.034>transform <00:25:54.175>and <00:25:54.314>then <00:25:54.455>and <00:25:54.595>join.

689
00:25:56.495 --> 00:25:58.715
<00:25:56.495>And <00:25:56.635>then <00:25:56.774>we've <00:25:56.915>got <00:25:57.054>some <00:25:57.195>way <00:25:57.334>to <00:25:57.475>like <00:25:57.614>construct <00:25:57.754>a <00:25:57.895>value.

690
00:25:59.375 --> 00:26:02.475
<00:25:59.375>And <00:25:59.502>this <00:25:59.629>allows <00:25:59.756>you <00:25:59.884>to <00:26:00.011>sort <00:26:00.138>of <00:26:00.265>view <00:26:00.393>them <00:26:00.520>as <00:26:00.647>some <00:26:00.775>box

691
00:26:02.475 --> 00:26:04.315
<00:26:02.475>of <00:26:02.675>some <00:26:02.875>value <00:26:03.074>that <00:26:03.274>can <00:26:03.475>be <00:26:03.675>transformed <00:26:03.875>while

692
00:26:04.315 --> 00:26:05.355
<00:26:04.315>keeping <00:26:04.549>it <00:26:04.783>inside <00:26:05.017>the <00:26:05.251>box.

693
00:26:05.695 --> 00:26:07.275
<00:26:05.695>And <00:26:05.928>this <00:26:06.161>is <00:26:06.395>what <00:26:06.628>enables <00:26:06.861>the <00:26:07.095>composition

694
00:26:07.345 --> 00:26:10.275
<00:26:07.345>because <00:26:07.520>you <00:26:07.695>can <00:26:07.870>very <00:26:08.045>straightforwardly <00:26:08.220>compose <00:26:08.395>the <00:26:08.570>boxes <00:26:08.745>in

695
00:26:10.275 --> 00:26:12.155
<00:26:10.275>some <00:26:10.508>way <00:26:10.741>given <00:26:10.975>based <00:26:11.208>on <00:26:11.441>the <00:26:11.675>transform.

696
00:26:12.155 --> 00:26:14.555
<00:26:12.155>And <00:26:12.310>then, <00:26:12.466>and <00:26:12.621>that <00:26:12.777>way <00:26:12.932>you <00:26:13.088>can <00:26:13.243>write <00:26:13.399>range <00:26:13.555>algorithms

697
00:26:14.555 --> 00:26:17.195
<00:26:14.555>that <00:26:14.755>compose, <00:26:14.955>you <00:26:15.155>can <00:26:15.355>compose <00:26:15.555>error <00:26:15.755>handling, <00:26:15.955>um,

698
00:26:17.215 --> 00:26:19.075
<00:26:17.215>you <00:26:17.415>can <00:26:17.615>compose <00:26:17.814>ao, <00:26:18.014>you <00:26:18.215>can <00:26:18.415>do <00:26:18.615>concurrency.

699
00:26:19.575 --> 00:26:21.635
<00:26:19.575>And <00:26:19.750>this <00:26:19.925>is <00:26:20.100>why <00:26:20.275>Mons <00:26:20.450>are <00:26:20.625>really <00:26:20.800>so <00:26:20.975>essential

700
00:26:21.635 --> 00:26:23.835
<00:26:21.635>to <00:26:21.915>functional <00:26:22.195>programming <00:26:22.475>because <00:26:22.754>functional <00:26:23.035>programming

701
00:26:23.835 --> 00:26:24.875
<00:26:23.835>is <00:26:24.147>all <00:26:24.459>about <00:26:24.771>composition.

702
00:26:25.055 --> 00:26:26.915
<00:26:25.055>And <00:26:25.335>mons <00:26:25.615>are <00:26:25.895>what <00:26:26.175>enable <00:26:26.455>composition.

703
00:26:27.335 --> 00:26:29.475
<00:26:27.335>So <00:26:27.490>in <00:26:27.646>c <00:26:27.801>plus <00:26:27.957>plus, <00:26:28.112>write <00:26:28.268>your <00:26:28.423>building <00:26:28.579>blocks <00:26:28.735>using

704
00:26:29.715 --> 00:26:31.795
<00:26:29.715>efficient, <00:26:29.915>optimized, <00:26:30.115>and <00:26:30.314>well <00:26:30.514>tested <00:26:30.715>c <00:26:30.915>plus <00:26:31.115>passcode

705
00:26:31.895 --> 00:26:34.435
<00:26:31.895>and <00:26:32.128>then <00:26:32.361>compose <00:26:32.595>them <00:26:32.828>using <00:26:33.061>functional <00:26:33.295>paradigms.

706
00:26:35.325 --> 00:26:37.035
<00:26:35.325>Asset <00:26:35.525>I <00:26:35.725>work <00:26:35.925>at <00:26:36.125>think <00:26:36.325>so <00:26:36.525>be <00:26:36.725>hiring.

707
00:26:37.335 --> 00:26:39.075
<00:26:37.335>So <00:26:37.475>if <00:26:37.615>you're <00:26:37.755>looking <00:26:37.895>for <00:26:38.035>a <00:26:38.175>new <00:26:38.315>c <00:26:38.455>plus <00:26:38.595>plus <00:26:38.735>job

708
00:26:39.335 --> 00:26:41.875
<00:26:39.335>and <00:26:39.568>like <00:26:39.801>declarative <00:26:40.035>range <00:26:40.268>of <00:26:40.501>style <00:26:40.735>programming

709
00:26:41.895 --> 00:26:45.075
<00:26:41.895>and <00:26:42.050>also <00:26:42.206>PowerPoint <00:26:42.361>for <00:26:42.517>some <00:26:42.672>reason, <00:26:42.828>um, <00:26:42.983>consider <00:26:43.139>we <00:26:43.295>are,

710
00:26:45.175 --> 00:26:46.315
<00:26:45.175>we <00:26:45.346>are <00:26:45.517>doing <00:26:45.688>some <00:26:45.859>pretty <00:26:46.030>cool <00:26:46.201>stuff.

711
00:26:46.315 --> 00:26:47.795
<00:26:46.315>Talk <00:26:46.505>to <00:26:46.695>me <00:26:46.885>later. <00:26:47.076>Thank <00:26:47.266>you <00:26:47.456>very <00:26:47.647>much.