Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help make unapply explainer a little more clear #179

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading