@@ -86,7 +86,10 @@ object HigherOrderFunctions
8686 result2 should be(res1)
8787 }
8888
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:
9093 */
9194 def holdEnvironmentHigherOrderFunctions (res0 : Int , res1 : Int ) {
9295 def summation (x : Int , y : Int ⇒ Int ) = y(x)
@@ -102,7 +105,7 @@ object HigherOrderFunctions
102105 result2 should be(res1)
103106 }
104107
105- /** Function returning another function:
108+ /** Higher Order Function returning another function:
106109 */
107110 def returningFunctionHigherOrderFunctions (res0 : Boolean , res1 : Int , res2 : Int ) {
108111 def addWithoutSyntaxSugar (x : Int ): Function1 [Int , Int ] = {
@@ -145,7 +148,8 @@ object HigherOrderFunctions
145148 def functionAsParameterHigherOrderFunctions (
146149 res0 : List [String ],
147150 res1 : List [String ],
148- res2 : List [Int ]) {
151+ res2 : List [String ],
152+ res3 : List [Int ]) {
149153 def makeUpper (xs : List [String ]) = xs map {
150154 _.toUpperCase
151155 }
@@ -160,9 +164,10 @@ object HigherOrderFunctions
160164 }) should be(res1)
161165
162166 // 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)
166171 }
167172
168173}
0 commit comments