You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3.3_higher-order_functions.ipynb
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -90,22 +90,22 @@
90
90
"\n",
91
91
"## Different ways of specifying functions\n",
92
92
"You may have noticed that there were two ways of specifying functions in the examples above:\n",
93
-
"- For functions where each argument is referred to exactly once, you *may* be able to use an underscore (`_`) to refer to each argument. In the example above, the `reduce` argument function took two arguments and could be specified as `_ + _`. While convenient, this is subject to an additional set of arcane rules, so if it does't work, try:\n",
93
+
"- For functions where each argument is referred to exactly once, you *may* be able to use an underscore (`_`) to refer to each argument. In the example above, the `reduce` argument function took two arguments and could be specified as `_ + _`. While convenient, this is subject to an additional set of arcane rules, so if it doesn't work, try:\n",
94
94
"- Specifying the inputs argument list explicitly. The reduce could have been explicitly written as `(a, b) => a + b`, with the general form of putting the argument list in parentheses, followed by `=>`, followed by the function body referring to those arguments.\n",
95
95
"- When tuple unpacking is needed, using a `case` statement, as in `case (a, b) => a * b`. That takes a single argument, a tuple of two elements, and unpacks it into variables `a` and `b`, which can then be used in the function body.\n",
96
96
"\n",
97
97
"## Practice in Scala\n",
98
98
"In the last module, we've seen major classes in the Scala Collections API, like `List`s.\n",
99
99
"These higher-order functions are part of these APIs - and in fact, the above example uses the `map` and `reduce` API on `List`s.\n",
100
100
"In this section, we'll familiarize ourselves with these methods through examples and exercises.\n",
101
-
"In these examples, we'll operate on Scala numbers (`Int`s) for the sake of simpliciy and clarify, but because Chisel operators behave similarly, the concepts should generalize.\n",
101
+
"In these examples, we'll operate on Scala numbers (`Int`s) for the sake of simplicity and clarity, but because Chisel operators behave similarly, the concepts should generalize.\n",
"`List[A].map` has type signature `map[B](f: (A) ⇒ B): List[B]`. You'll learn more about types in a later module. For now, think of types A and B as `Int`s or `UInt`s, meaning they could be software or hardware types.\n",
105
105
"\n",
106
106
"In plain English, it takes an argument of type `(f: (A) ⇒ B)`, or a function that takes one argument of type `A` (the same type as the element of the input List) and returns a value of type `B` (which can be anything). `map` then returns a new list of type `B` (the return type of the argument function).\n",
107
107
"\n",
108
-
"As we've already explained the behavior of List in the FIR explanation, let's get straight into the examples and exercises:"
108
+
"As we've already explained the behavior of List in the FIR example, let's get straight into the examples and exercises:"
109
109
]
110
110
},
111
111
{
@@ -158,9 +158,9 @@
158
158
"It takes no arguments, but returns a list where each element is a tuple of the original elements, and the index (with the first one being zero).\n",
0 commit comments