Skip to content

Commit 8c24b2e

Browse files
authored
more examples in HigherOrderFunctions
1 parent b81f080 commit 8c24b2e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/scala/stdlib/HigherOrderFunctions.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ object HigherOrderFunctions
145145
def functionAsParameterHigherOrderFunctions(
146146
res0: List[String],
147147
res1: List[String],
148-
res2: List[Int]) {
148+
res2: List[String],
149+
res3: List[Int]) {
149150
def makeUpper(xs: List[String]) = xs map {
150151
_.toUpperCase
151152
}
@@ -154,15 +155,17 @@ object HigherOrderFunctions
154155
xs map sideEffect
155156

156157
makeUpper(List("abc", "xyz", "123")) should be(res0)
157-
158+
158159
makeWhatEverYouLike(List("ABC", "XYZ", "123"), { x
159160
x.toLowerCase
160161
}) should be(res1)
161162

163+
162164
//using it inline
163-
List("Scala", "Erlang", "Clojure") map {
164-
_.length
165-
} should be(res2)
165+
val myName = (name: String) => s"My name is $name"
166+
makeWhatEverYouLike(List("John", "Mark"), myName) should be(res2)
167+
168+
List("Scala", "Erlang", "Clojure") map (_.length) should be(res3)
166169
}
167170

168171
}

0 commit comments

Comments
 (0)