Skip to content

Commit 032dcde

Browse files
committed
Moved underscore tutorial to Scala 2 module
1 parent 53b1406 commit 032dcde

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

scala-2-modules/scala2-core/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
- [Introduction to Macros in Scala 2](https://www.baeldung.com/scala/scala2-macros)
99
- [Demystifying View and Context Bounds](https://www.baeldung.com/scala/view-context-bounds)
1010
- [Introduction to Scala](https://www.baeldung.com/scala/scala-intro)
11-
- [Exception Handling in Scala](https://www.baeldung.com/scala/exception-handling)
11+
- [Exception Handling in Scala](https://www.baeldung.com/scala/exception-handling)
12+
- [Usages of Underscore (_) in Scala](https://www.baeldung.com/scala/underscore)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.baeldung.scala.underscore
22

33
object UnderscoreUsages {
44

5-
def getLength(x: List[List[?]]): Int = x.length
5+
def getLength(x: List[List[_]]): Int = x.length
66

77
def itemTransaction(price: Double): String = {
88
price match {
@@ -33,7 +33,7 @@ object UnderscoreUsages {
3333
}
3434
}
3535

36-
def list_++(list: List[?]): List[?] = List.concat(list, list)
36+
def list_++(list: List[_]): List[_] = List.concat(list, list)
3737

3838
trait ObjectContainer[T[_]] { // higher kinded type parameter
3939
def checkIfEmpty[A](collection: T[A]): Boolean
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.baeldung.scala.underscore
22

3-
import com.baeldung.scala.underscore.UnderscoreUsages._
43
import org.scalatest.matchers.should.Matchers
54
import org.scalatest.wordspec.AnyWordSpec
5+
import UnderscoreUsages._
6+
67
class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
78

89
"The underscore" should {
@@ -58,20 +59,20 @@ class UnderscoreUsagesUnitTest extends AnyWordSpec with Matchers {
5859
e shouldBe "e"
5960
}
6061
"work in reassigning a a function to a value" in {
61-
val times = multiplier
62+
val times = multiplier _
6263
multiplier(8, 13) shouldBe times(8, 13)
6364
}
6465
"work in converting a sequence to variable arguments" in {
6566
val sumable = Seq(4, 5, 10, 3)
66-
val sumOfSumable = sum(sumable*)
67+
val sumOfSumable = sum(sumable: _*)
6768
sumOfSumable shouldBe 22
6869
}
6970
"generate a partially applied function" in {
7071
val sumToTen = sum(10, _: Int)
7172
val sumFiveAndTen = sumToTen(5)
7273
sumFiveAndTen shouldBe 15
7374

74-
val foo = bar(1, 2)
75+
val foo = bar(1, 2) _
7576
foo("Some string", "Another string")(3 / 5, 6 / 5) shouldBe 1
7677
}
7778
"work in overriding a method's setter" in {

scala-core-modules/scala-core-2/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This module contains articles about Scala's core features.
99
- [Futures and Promises in Scala](https://www.baeldung.com/scala/futures-promises)
1010
- [Named and Default Arguments in Scala](https://www.baeldung.com/scala/named-default-arguments)
1111
- [Self-Type Annotation in Scala](https://www.baeldung.com/scala/self-type-annotation)
12-
- [Usages of Underscore (_) in Scala](https://www.baeldung.com/scala/underscore)
1312
- [A DSL for Writing “20 seconds” in Scala](https://www.baeldung.com/scala/dsl-writing-20-seconds)
1413
- [Error Handling in Scala](https://www.baeldung.com/scala/error-handling)
1514
- [Higher-Kinded Types](https://www.baeldung.com/scala/higher-kinded-types)

0 commit comments

Comments
 (0)