@@ -86,7 +86,10 @@ object HigherOrderFunctions
86
86
result2 should be(res1)
87
87
}
88
88
89
- /** We can take that closure and throw it into a method and it will still hold the environment:
89
+ /** And then we get to Higher Order Functions:
90
+ * Higher Order Functions are functions that take functions as arguments and/or return functions.
91
+ *
92
+ * We can take that closure and throw it into a Higher Order Function and it will still hold the environment:
90
93
*/
91
94
def holdEnvironmentHigherOrderFunctions (res0 : Int , res1 : Int ) {
92
95
def summation (x : Int , y : Int ⇒ Int ) = y(x)
@@ -102,7 +105,7 @@ object HigherOrderFunctions
102
105
result2 should be(res1)
103
106
}
104
107
105
- /** Function returning another function:
108
+ /** Higher Order Function returning another function:
106
109
*/
107
110
def returningFunctionHigherOrderFunctions (res0 : Boolean , res1 : Int , res2 : Int ) {
108
111
def addWithoutSyntaxSugar (x : Int ): Function1 [Int , Int ] = {
@@ -145,7 +148,8 @@ object HigherOrderFunctions
145
148
def functionAsParameterHigherOrderFunctions (
146
149
res0 : List [String ],
147
150
res1 : List [String ],
148
- res2 : List [Int ]) {
151
+ res2 : List [String ],
152
+ res3 : List [Int ]) {
149
153
def makeUpper (xs : List [String ]) = xs map {
150
154
_.toUpperCase
151
155
}
@@ -160,9 +164,10 @@ object HigherOrderFunctions
160
164
}) should be(res1)
161
165
162
166
// using it inline
163
- List (" Scala" , " Erlang" , " Clojure" ) map {
164
- _.length
165
- } should be(res2)
167
+ val myName = (name : String ) => s " My name is $name"
168
+ makeWhatEverYouLike(List (" John" , " Mark" ), myName) should be(res2)
169
+
170
+ List (" Scala" , " Erlang" , " Clojure" ) map (_.length) should be(res3)
166
171
}
167
172
168
173
}
0 commit comments