Skip to content

Commit

Permalink
Help make unapply explainer a little more clear (#179)
Browse files Browse the repository at this point in the history
* Help make unapply a little more clear
* Made spacing after `@` operator consistent for syntax highlighting
  • Loading branch information
JL102 authored Jun 16, 2023
1 parent 3e0d0eb commit f27b334
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions 3.6_types.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"top\"></a><img src=\"images/chisel_1024.png\" alt=\"Chisel logo\" style=\"width:480px;\" />"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -50,6 +52,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -74,6 +77,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -93,6 +97,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -114,6 +119,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -134,6 +140,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -169,6 +176,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -179,6 +187,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"collapsed": true
Expand Down Expand Up @@ -207,6 +216,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -247,6 +257,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -284,6 +295,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -313,12 +325,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unapply\n",
"What's actually going on when you do a match?\n",
"Why can you do fancy value matching with case classes like this:\n",
"How does Scala let you do fancy value matching with case classes like this:\n",
"```scala\n",
"case class Something(a: String, b: Int)\n",
"val a = Something(\"A\", 3)\n",
Expand Down Expand Up @@ -355,15 +368,16 @@
"}\n",
"\n",
"def delay(p: SomeGeneratorParameters): Int = p match {\n",
" case sg @ SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n",
" case SomeGeneratorParameters(_, sw, false) => sw * 2\n",
" case sg @SomeGeneratorParameters(_, _, true) => sg.totalWidth * 3\n",
"}\n",
"\n",
"println(delay(SomeGeneratorParameters(10, 10)))\n",
"println(delay(SomeGeneratorParameters(10, 10, true)))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -377,16 +391,16 @@
"case SomeGeneratorParameters(_, sw, _) => sw * 2\n",
"```\n",
"\n",
"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",
"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",
"```scala\n",
"case SomeGeneratorParameters(_, sw, true) => sw\n",
"case sg@SomeGeneratorParameters(_, sw, true) => sw\n",
"case sg @SomeGeneratorParameters(_, sw, true) => sw\n",
"```\n",
"\n",
"Finally, you can directly embed condition checking into match statements, as demonstrated by the third of these equivalent examples:\n",
"```scala\n",
"case SomeGeneratorParameters(_, sw, false) => sw * 2\n",
"case s@SomeGeneratorParameters(_, sw, false) => s.sw * 2\n",
"case s @SomeGeneratorParameters(_, sw, false) => s.sw * 2\n",
"case s: SomeGeneratorParameters if s.pipelineMe => s.sw * 2\n",
"```\n",
"\n",
Expand Down Expand Up @@ -417,6 +431,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -482,6 +497,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -533,6 +549,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -557,6 +574,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -580,6 +598,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -613,6 +632,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -632,6 +652,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -683,6 +704,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -691,6 +713,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -738,6 +761,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -782,6 +806,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -797,6 +822,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -838,6 +864,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -862,6 +889,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -874,6 +902,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -907,6 +936,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1004,6 +1034,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1020,6 +1051,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -1036,6 +1068,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down

0 comments on commit f27b334

Please sign in to comment.