Skip to content

Commit f27b334

Browse files
authored
Help make unapply explainer a little more clear (freechipsproject#179)
* Help make unapply a little more clear * Made spacing after `@` operator consistent for syntax highlighting
1 parent 3e0d0eb commit f27b334

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

3.6_types.ipynb

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"cells": [
33
{
4+
"attachments": {},
45
"cell_type": "markdown",
56
"metadata": {},
67
"source": [
78
"<a name=\"top\"></a><img src=\"images/chisel_1024.png\" alt=\"Chisel logo\" style=\"width:480px;\" />"
89
]
910
},
1011
{
12+
"attachments": {},
1113
"cell_type": "markdown",
1214
"metadata": {},
1315
"source": [
@@ -50,6 +52,7 @@
5052
]
5153
},
5254
{
55+
"attachments": {},
5356
"cell_type": "markdown",
5457
"metadata": {},
5558
"source": [
@@ -74,6 +77,7 @@
7477
]
7578
},
7679
{
80+
"attachments": {},
7781
"cell_type": "markdown",
7882
"metadata": {},
7983
"source": [
@@ -93,6 +97,7 @@
9397
]
9498
},
9599
{
100+
"attachments": {},
96101
"cell_type": "markdown",
97102
"metadata": {},
98103
"source": [
@@ -114,6 +119,7 @@
114119
]
115120
},
116121
{
122+
"attachments": {},
117123
"cell_type": "markdown",
118124
"metadata": {},
119125
"source": [
@@ -134,6 +140,7 @@
134140
]
135141
},
136142
{
143+
"attachments": {},
137144
"cell_type": "markdown",
138145
"metadata": {},
139146
"source": [
@@ -169,6 +176,7 @@
169176
]
170177
},
171178
{
179+
"attachments": {},
172180
"cell_type": "markdown",
173181
"metadata": {},
174182
"source": [
@@ -179,6 +187,7 @@
179187
]
180188
},
181189
{
190+
"attachments": {},
182191
"cell_type": "markdown",
183192
"metadata": {
184193
"collapsed": true
@@ -207,6 +216,7 @@
207216
]
208217
},
209218
{
219+
"attachments": {},
210220
"cell_type": "markdown",
211221
"metadata": {},
212222
"source": [
@@ -247,6 +257,7 @@
247257
]
248258
},
249259
{
260+
"attachments": {},
250261
"cell_type": "markdown",
251262
"metadata": {},
252263
"source": [
@@ -284,6 +295,7 @@
284295
]
285296
},
286297
{
298+
"attachments": {},
287299
"cell_type": "markdown",
288300
"metadata": {},
289301
"source": [
@@ -313,12 +325,13 @@
313325
]
314326
},
315327
{
328+
"attachments": {},
316329
"cell_type": "markdown",
317330
"metadata": {},
318331
"source": [
319332
"## Unapply\n",
320333
"What's actually going on when you do a match?\n",
321-
"Why can you do fancy value matching with case classes like this:\n",
334+
"How does Scala let you do fancy value matching with case classes like this:\n",
322335
"```scala\n",
323336
"case class Something(a: String, b: Int)\n",
324337
"val a = Something(\"A\", 3)\n",
@@ -355,15 +368,16 @@
355368
"}\n",
356369
"\n",
357370
"def delay(p: SomeGeneratorParameters): Int = p match {\n",
358-
" case sg @ SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n",
359371
" case SomeGeneratorParameters(_, sw, false) => sw * 2\n",
372+
" case sg @SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n",
360373
"}\n",
361374
"\n",
362375
"println(delay(SomeGeneratorParameters(10, 10)))\n",
363376
"println(delay(SomeGeneratorParameters(10, 10, true)))"
364377
]
365378
},
366379
{
380+
"attachments": {},
367381
"cell_type": "markdown",
368382
"metadata": {},
369383
"source": [
@@ -377,16 +391,16 @@
377391
"case SomeGeneratorParameters(_, sw, _) => sw * 2\n",
378392
"```\n",
379393
"\n",
380-
"In addition, there are more syntaxes and styles of matching. The following two cases are also equivalent, but the second allows you to match on internal values while still reference the parent value:\n",
394+
"In addition, there are more syntaxes and styles of matching. The following two cases are also equivalent, but the second allows you to match on internal values while still referencing the parent value:\n",
381395
"```scala\n",
382396
"case SomeGeneratorParameters(_, sw, true) => sw\n",
383-
"case sg@SomeGeneratorParameters(_, sw, true) => sw\n",
397+
"case sg @SomeGeneratorParameters(_, sw, true) => sw\n",
384398
"```\n",
385399
"\n",
386400
"Finally, you can directly embed condition checking into match statements, as demonstrated by the third of these equivalent examples:\n",
387401
"```scala\n",
388402
"case SomeGeneratorParameters(_, sw, false) => sw * 2\n",
389-
"case s@SomeGeneratorParameters(_, sw, false) => s.sw * 2\n",
403+
"case s @SomeGeneratorParameters(_, sw, false) => s.sw * 2\n",
390404
"case s: SomeGeneratorParameters if s.pipelineMe => s.sw * 2\n",
391405
"```\n",
392406
"\n",
@@ -417,6 +431,7 @@
417431
]
418432
},
419433
{
434+
"attachments": {},
420435
"cell_type": "markdown",
421436
"metadata": {},
422437
"source": [
@@ -482,6 +497,7 @@
482497
]
483498
},
484499
{
500+
"attachments": {},
485501
"cell_type": "markdown",
486502
"metadata": {},
487503
"source": [
@@ -533,6 +549,7 @@
533549
]
534550
},
535551
{
552+
"attachments": {},
536553
"cell_type": "markdown",
537554
"metadata": {},
538555
"source": [
@@ -557,6 +574,7 @@
557574
]
558575
},
559576
{
577+
"attachments": {},
560578
"cell_type": "markdown",
561579
"metadata": {},
562580
"source": [
@@ -580,6 +598,7 @@
580598
]
581599
},
582600
{
601+
"attachments": {},
583602
"cell_type": "markdown",
584603
"metadata": {},
585604
"source": [
@@ -613,6 +632,7 @@
613632
]
614633
},
615634
{
635+
"attachments": {},
616636
"cell_type": "markdown",
617637
"metadata": {},
618638
"source": [
@@ -632,6 +652,7 @@
632652
]
633653
},
634654
{
655+
"attachments": {},
635656
"cell_type": "markdown",
636657
"metadata": {},
637658
"source": [
@@ -683,6 +704,7 @@
683704
]
684705
},
685706
{
707+
"attachments": {},
686708
"cell_type": "markdown",
687709
"metadata": {},
688710
"source": [
@@ -691,6 +713,7 @@
691713
]
692714
},
693715
{
716+
"attachments": {},
694717
"cell_type": "markdown",
695718
"metadata": {},
696719
"source": [
@@ -738,6 +761,7 @@
738761
]
739762
},
740763
{
764+
"attachments": {},
741765
"cell_type": "markdown",
742766
"metadata": {},
743767
"source": [
@@ -782,6 +806,7 @@
782806
]
783807
},
784808
{
809+
"attachments": {},
785810
"cell_type": "markdown",
786811
"metadata": {},
787812
"source": [
@@ -797,6 +822,7 @@
797822
]
798823
},
799824
{
825+
"attachments": {},
800826
"cell_type": "markdown",
801827
"metadata": {},
802828
"source": [
@@ -838,6 +864,7 @@
838864
]
839865
},
840866
{
867+
"attachments": {},
841868
"cell_type": "markdown",
842869
"metadata": {},
843870
"source": [
@@ -862,6 +889,7 @@
862889
]
863890
},
864891
{
892+
"attachments": {},
865893
"cell_type": "markdown",
866894
"metadata": {},
867895
"source": [
@@ -874,6 +902,7 @@
874902
]
875903
},
876904
{
905+
"attachments": {},
877906
"cell_type": "markdown",
878907
"metadata": {},
879908
"source": [
@@ -907,6 +936,7 @@
907936
]
908937
},
909938
{
939+
"attachments": {},
910940
"cell_type": "markdown",
911941
"metadata": {},
912942
"source": [
@@ -1004,6 +1034,7 @@
10041034
]
10051035
},
10061036
{
1037+
"attachments": {},
10071038
"cell_type": "markdown",
10081039
"metadata": {},
10091040
"source": [
@@ -1020,6 +1051,7 @@
10201051
]
10211052
},
10221053
{
1054+
"attachments": {},
10231055
"cell_type": "markdown",
10241056
"metadata": {},
10251057
"source": [
@@ -1036,6 +1068,7 @@
10361068
]
10371069
},
10381070
{
1071+
"attachments": {},
10391072
"cell_type": "markdown",
10401073
"metadata": {},
10411074
"source": [

0 commit comments

Comments
 (0)