|
1 | 1 | { |
2 | 2 | "cells": [ |
3 | 3 | { |
| 4 | + "attachments": {}, |
4 | 5 | "cell_type": "markdown", |
5 | 6 | "metadata": {}, |
6 | 7 | "source": [ |
7 | 8 | "<a name=\"top\"></a><img src=\"images/chisel_1024.png\" alt=\"Chisel logo\" style=\"width:480px;\" />" |
8 | 9 | ] |
9 | 10 | }, |
10 | 11 | { |
| 12 | + "attachments": {}, |
11 | 13 | "cell_type": "markdown", |
12 | 14 | "metadata": {}, |
13 | 15 | "source": [ |
|
50 | 52 | ] |
51 | 53 | }, |
52 | 54 | { |
| 55 | + "attachments": {}, |
53 | 56 | "cell_type": "markdown", |
54 | 57 | "metadata": {}, |
55 | 58 | "source": [ |
|
74 | 77 | ] |
75 | 78 | }, |
76 | 79 | { |
| 80 | + "attachments": {}, |
77 | 81 | "cell_type": "markdown", |
78 | 82 | "metadata": {}, |
79 | 83 | "source": [ |
|
93 | 97 | ] |
94 | 98 | }, |
95 | 99 | { |
| 100 | + "attachments": {}, |
96 | 101 | "cell_type": "markdown", |
97 | 102 | "metadata": {}, |
98 | 103 | "source": [ |
|
114 | 119 | ] |
115 | 120 | }, |
116 | 121 | { |
| 122 | + "attachments": {}, |
117 | 123 | "cell_type": "markdown", |
118 | 124 | "metadata": {}, |
119 | 125 | "source": [ |
|
134 | 140 | ] |
135 | 141 | }, |
136 | 142 | { |
| 143 | + "attachments": {}, |
137 | 144 | "cell_type": "markdown", |
138 | 145 | "metadata": {}, |
139 | 146 | "source": [ |
|
169 | 176 | ] |
170 | 177 | }, |
171 | 178 | { |
| 179 | + "attachments": {}, |
172 | 180 | "cell_type": "markdown", |
173 | 181 | "metadata": {}, |
174 | 182 | "source": [ |
|
179 | 187 | ] |
180 | 188 | }, |
181 | 189 | { |
| 190 | + "attachments": {}, |
182 | 191 | "cell_type": "markdown", |
183 | 192 | "metadata": { |
184 | 193 | "collapsed": true |
|
207 | 216 | ] |
208 | 217 | }, |
209 | 218 | { |
| 219 | + "attachments": {}, |
210 | 220 | "cell_type": "markdown", |
211 | 221 | "metadata": {}, |
212 | 222 | "source": [ |
|
247 | 257 | ] |
248 | 258 | }, |
249 | 259 | { |
| 260 | + "attachments": {}, |
250 | 261 | "cell_type": "markdown", |
251 | 262 | "metadata": {}, |
252 | 263 | "source": [ |
|
284 | 295 | ] |
285 | 296 | }, |
286 | 297 | { |
| 298 | + "attachments": {}, |
287 | 299 | "cell_type": "markdown", |
288 | 300 | "metadata": {}, |
289 | 301 | "source": [ |
|
313 | 325 | ] |
314 | 326 | }, |
315 | 327 | { |
| 328 | + "attachments": {}, |
316 | 329 | "cell_type": "markdown", |
317 | 330 | "metadata": {}, |
318 | 331 | "source": [ |
319 | 332 | "## Unapply\n", |
320 | 333 | "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", |
322 | 335 | "```scala\n", |
323 | 336 | "case class Something(a: String, b: Int)\n", |
324 | 337 | "val a = Something(\"A\", 3)\n", |
|
355 | 368 | "}\n", |
356 | 369 | "\n", |
357 | 370 | "def delay(p: SomeGeneratorParameters): Int = p match {\n", |
358 | | - " case sg @ SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n", |
359 | 371 | " case SomeGeneratorParameters(_, sw, false) => sw * 2\n", |
| 372 | + " case sg @SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n", |
360 | 373 | "}\n", |
361 | 374 | "\n", |
362 | 375 | "println(delay(SomeGeneratorParameters(10, 10)))\n", |
363 | 376 | "println(delay(SomeGeneratorParameters(10, 10, true)))" |
364 | 377 | ] |
365 | 378 | }, |
366 | 379 | { |
| 380 | + "attachments": {}, |
367 | 381 | "cell_type": "markdown", |
368 | 382 | "metadata": {}, |
369 | 383 | "source": [ |
|
377 | 391 | "case SomeGeneratorParameters(_, sw, _) => sw * 2\n", |
378 | 392 | "```\n", |
379 | 393 | "\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", |
381 | 395 | "```scala\n", |
382 | 396 | "case SomeGeneratorParameters(_, sw, true) => sw\n", |
383 | | - "case sg@SomeGeneratorParameters(_, sw, true) => sw\n", |
| 397 | + "case sg @SomeGeneratorParameters(_, sw, true) => sw\n", |
384 | 398 | "```\n", |
385 | 399 | "\n", |
386 | 400 | "Finally, you can directly embed condition checking into match statements, as demonstrated by the third of these equivalent examples:\n", |
387 | 401 | "```scala\n", |
388 | 402 | "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", |
390 | 404 | "case s: SomeGeneratorParameters if s.pipelineMe => s.sw * 2\n", |
391 | 405 | "```\n", |
392 | 406 | "\n", |
|
417 | 431 | ] |
418 | 432 | }, |
419 | 433 | { |
| 434 | + "attachments": {}, |
420 | 435 | "cell_type": "markdown", |
421 | 436 | "metadata": {}, |
422 | 437 | "source": [ |
|
482 | 497 | ] |
483 | 498 | }, |
484 | 499 | { |
| 500 | + "attachments": {}, |
485 | 501 | "cell_type": "markdown", |
486 | 502 | "metadata": {}, |
487 | 503 | "source": [ |
|
533 | 549 | ] |
534 | 550 | }, |
535 | 551 | { |
| 552 | + "attachments": {}, |
536 | 553 | "cell_type": "markdown", |
537 | 554 | "metadata": {}, |
538 | 555 | "source": [ |
|
557 | 574 | ] |
558 | 575 | }, |
559 | 576 | { |
| 577 | + "attachments": {}, |
560 | 578 | "cell_type": "markdown", |
561 | 579 | "metadata": {}, |
562 | 580 | "source": [ |
|
580 | 598 | ] |
581 | 599 | }, |
582 | 600 | { |
| 601 | + "attachments": {}, |
583 | 602 | "cell_type": "markdown", |
584 | 603 | "metadata": {}, |
585 | 604 | "source": [ |
|
613 | 632 | ] |
614 | 633 | }, |
615 | 634 | { |
| 635 | + "attachments": {}, |
616 | 636 | "cell_type": "markdown", |
617 | 637 | "metadata": {}, |
618 | 638 | "source": [ |
|
632 | 652 | ] |
633 | 653 | }, |
634 | 654 | { |
| 655 | + "attachments": {}, |
635 | 656 | "cell_type": "markdown", |
636 | 657 | "metadata": {}, |
637 | 658 | "source": [ |
|
683 | 704 | ] |
684 | 705 | }, |
685 | 706 | { |
| 707 | + "attachments": {}, |
686 | 708 | "cell_type": "markdown", |
687 | 709 | "metadata": {}, |
688 | 710 | "source": [ |
|
691 | 713 | ] |
692 | 714 | }, |
693 | 715 | { |
| 716 | + "attachments": {}, |
694 | 717 | "cell_type": "markdown", |
695 | 718 | "metadata": {}, |
696 | 719 | "source": [ |
|
738 | 761 | ] |
739 | 762 | }, |
740 | 763 | { |
| 764 | + "attachments": {}, |
741 | 765 | "cell_type": "markdown", |
742 | 766 | "metadata": {}, |
743 | 767 | "source": [ |
|
782 | 806 | ] |
783 | 807 | }, |
784 | 808 | { |
| 809 | + "attachments": {}, |
785 | 810 | "cell_type": "markdown", |
786 | 811 | "metadata": {}, |
787 | 812 | "source": [ |
|
797 | 822 | ] |
798 | 823 | }, |
799 | 824 | { |
| 825 | + "attachments": {}, |
800 | 826 | "cell_type": "markdown", |
801 | 827 | "metadata": {}, |
802 | 828 | "source": [ |
|
838 | 864 | ] |
839 | 865 | }, |
840 | 866 | { |
| 867 | + "attachments": {}, |
841 | 868 | "cell_type": "markdown", |
842 | 869 | "metadata": {}, |
843 | 870 | "source": [ |
|
862 | 889 | ] |
863 | 890 | }, |
864 | 891 | { |
| 892 | + "attachments": {}, |
865 | 893 | "cell_type": "markdown", |
866 | 894 | "metadata": {}, |
867 | 895 | "source": [ |
|
874 | 902 | ] |
875 | 903 | }, |
876 | 904 | { |
| 905 | + "attachments": {}, |
877 | 906 | "cell_type": "markdown", |
878 | 907 | "metadata": {}, |
879 | 908 | "source": [ |
|
907 | 936 | ] |
908 | 937 | }, |
909 | 938 | { |
| 939 | + "attachments": {}, |
910 | 940 | "cell_type": "markdown", |
911 | 941 | "metadata": {}, |
912 | 942 | "source": [ |
|
1004 | 1034 | ] |
1005 | 1035 | }, |
1006 | 1036 | { |
| 1037 | + "attachments": {}, |
1007 | 1038 | "cell_type": "markdown", |
1008 | 1039 | "metadata": {}, |
1009 | 1040 | "source": [ |
|
1020 | 1051 | ] |
1021 | 1052 | }, |
1022 | 1053 | { |
| 1054 | + "attachments": {}, |
1023 | 1055 | "cell_type": "markdown", |
1024 | 1056 | "metadata": {}, |
1025 | 1057 | "source": [ |
|
1036 | 1068 | ] |
1037 | 1069 | }, |
1038 | 1070 | { |
| 1071 | + "attachments": {}, |
1039 | 1072 | "cell_type": "markdown", |
1040 | 1073 | "metadata": {}, |
1041 | 1074 | "source": [ |
|
0 commit comments