Skip to content

Commit afa5f41

Browse files
committed
resolved conflicts
2 parents c8b06da + 857aca9 commit afa5f41

File tree

8 files changed

+175
-11
lines changed

8 files changed

+175
-11
lines changed

build.sbt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ lazy val scala2_core = (project in file("scala-core-modules/scala2-core"))
6161
libraryDependencies += scalaReflection,
6262
libraryDependencies += scalaXmlDep,
6363
libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0",
64-
libraryDependencies += "org.rogach" %% "scallop" % "5.0.1",
64+
libraryDependencies += "org.rogach" %% "scallop" % "5.1.0",
6565
libraryDependencies += "org.backuity.clist" %% "clist-core" % "3.5.1",
6666
libraryDependencies += "org.backuity.clist" %% "clist-macros" % "3.5.1" % "provided",
6767
libraryDependencies += "args4j" % "args4j" % "2.37",
@@ -116,7 +116,8 @@ lazy val scala_core_9 = (project in file("scala-core-modules/scala-core-9"))
116116
.settings(
117117
name := "scala-core-9",
118118
libraryDependencies ++= scalaTestDeps,
119-
scalaVersion := scala3Version
119+
scalaVersion := scala3Version,
120+
libraryDependencies += "org.scalatestplus" %% "scalacheck-1-17" % "3.2.18.0" % Test
120121
)
121122

122123
lazy val scala_core_io = (project in file("scala-core-modules/scala-core-io"))
@@ -316,7 +317,7 @@ val monocleVersion = "2.1.0"
316317
val slickVersion = "3.5.0"
317318
val shapelessVersion = "2.3.10"
318319
val scalazVersion = "7.3.8"
319-
val fs2Version = "3.9.4"
320+
val fs2Version = "3.10.0"
320321
val reactiveMongo = "1.1.0-RC12"
321322

322323
lazy val scala2_libraries = (project in file("scala-2-modules/scala2-libraries"))
@@ -397,7 +398,7 @@ lazy val scala_libraries = (project in file("scala-libraries"))
397398
),
398399
libraryDependencies ++= Seq(
399400
"org.playframework" %% "play-slick" % "6.1.0",
400-
"org.postgresql" % "postgresql" % "42.7.2"
401+
"org.postgresql" % "postgresql" % "42.7.3"
401402
),
402403
dependencyOverrides := Seq(
403404
"com.typesafe.akka" %% "akka-protobuf-v3" % AkkaVersion,
@@ -461,7 +462,7 @@ lazy val tapir = (project in file("scala-libraries-standalone/tapir"))
461462
val spireVersion = "0.18.0"
462463
val kafkaVersion = "7.6.0-ce"
463464
val pureconfigVersion = "0.17.6"
464-
val jackSonVersion = "2.16.2"
465+
val jackSonVersion = "2.17.0"
465466
val log4jApiScalaVersion = "13.1.0"
466467
val log4jVersion = "2.20.0"
467468
val avro4sVersion = "4.1.2"
@@ -501,10 +502,10 @@ lazy val scala_libraries_testing = (project in file("scala-libraries-testing"))
501502
scalaMock,
502503
"com.lihaoyi" %% "utest" % "0.8.2" % "test",
503504
munitDep,
504-
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.679" % IntegrationTest,
505+
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.685" % IntegrationTest,
505506
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.41.3" % IntegrationTest,
506507
"com.dimafeng" %% "testcontainers-scala-localstack-v2" % "0.41.3" % IntegrationTest,
507-
"software.amazon.awssdk" % "s3" % "2.25.9"
508+
"software.amazon.awssdk" % "s3" % "2.25.15"
508509
),
509510
Defaults.itSettings,
510511
IntegrationTest / fork := true
@@ -611,7 +612,7 @@ lazy val zio = (project in file("zio"))
611612
libraryDependencies += "dev.zio" %% "zio" % zioVersion,
612613
libraryDependencies += "dev.zio" %% "zio-streams" % zioVersion,
613614
libraryDependencies += zioTestSbt,
614-
libraryDependencies += "dev.zio" %% "zio-kafka" % "2.7.3",
615+
libraryDependencies += "dev.zio" %% "zio-kafka" % "2.7.4",
615616
libraryDependencies += zioJsonDep,
616617
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
617618
)
@@ -631,8 +632,8 @@ lazy val zio3 = (project in file("zio3"))
631632
libraryDependencies ++= Seq(
632633
zioJsonDep,
633634
"dev.zio" %% "zio-http" % "3.0.0-RC2",
634-
"io.getquill" %% "quill-zio" % "4.8.1",
635-
"io.getquill" %% "quill-jdbc-zio" % "4.8.1",
635+
"io.getquill" %% "quill-zio" % "4.8.3",
636+
"io.getquill" %% "quill-jdbc-zio" % "4.8.3",
636637
"com.h2database" % "h2" % "2.2.220"
637638
),
638639
libraryDependencies ++= Seq(

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
22

33
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
4-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
4+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
55

66
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.2.1")
77
libraryDependencies += "ai.kien" %% "python-native-libs" % "0.2.4"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.scala.powerof2
2+
3+
import scala.annotation.tailrec
4+
5+
object PowerOfTwo {
6+
7+
def isPowerOfTwoByDivision(num: Long): Boolean = {
8+
@tailrec
9+
def isPowerRec(n: Long): Boolean = {
10+
if (n == 1) true
11+
else if (n % 2 == 0) isPowerRec(n / 2)
12+
else false
13+
}
14+
num > 0 && isPowerRec(num)
15+
}
16+
17+
def isPowerOfTwoByCountingOnes(num: Long): Boolean = {
18+
num > 0 && num.toBinaryString.count(_ == '1') == 1
19+
}
20+
21+
def isPowerOfTwoByBitwiseAnd(num: Long): Boolean = {
22+
num > 0 && (num & (num - 1)) == 0
23+
}
24+
25+
def isPowerOfTwoByLazyList(num: Long): Boolean = {
26+
num > 0 && LazyList.iterate(num)(_ / 2).takeWhile(_ > 1).forall(_ % 2 == 0)
27+
}
28+
29+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.baeldung.scala.powerof2
2+
3+
import org.scalacheck.Gen
4+
import org.scalatest.flatspec.AnyFlatSpec
5+
import org.scalatest.matchers.should.Matchers
6+
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
7+
8+
class PowerOfTwoUnitTest
9+
extends AnyFlatSpec
10+
with Matchers
11+
with ScalaCheckPropertyChecks {
12+
13+
private val powerOfTwoFunctions = Seq(
14+
("Division", PowerOfTwo.isPowerOfTwoByDivision),
15+
("Counting Ones", PowerOfTwo.isPowerOfTwoByCountingOnes),
16+
("Bitwise AND", PowerOfTwo.isPowerOfTwoByBitwiseAnd),
17+
("LazyList", PowerOfTwo.isPowerOfTwoByLazyList)
18+
)
19+
20+
powerOfTwoFunctions.foreach { (desc, fn) =>
21+
it should s"[$desc] return true for a number that is power of 2" in {
22+
val powersOfTwo: Gen[Long] =
23+
Gen.choose(0, 62).map(n => Math.pow(2, n).toLong)
24+
forAll(powersOfTwo) { num =>
25+
fn(num) shouldBe true
26+
}
27+
}
28+
29+
it should s"[$desc] return false for a number that is NOT a power of 2" in {
30+
val powersOfTwo: Gen[Long] =
31+
Gen.choose(0, 62).map(n => Math.pow(2, n).toLong)
32+
val notPowerOf2 = Gen
33+
.choose(0L, Long.MaxValue)
34+
.suchThat(n => !powersOfTwo.sample.contains(n))
35+
forAll(notPowerOf2) { num =>
36+
fn(num) shouldBe false
37+
}
38+
}
39+
40+
it should s"[$desc] return false for any negative numbers" in {
41+
val negativeNumbers = Gen.choose(Long.MinValue, 0L)
42+
forAll(negativeNumbers) { num =>
43+
fn(num) shouldBe false
44+
}
45+
}
46+
}
47+
48+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ This module contains articles about Scala's core features
1212
- [Introduction to Traits in Scala](https://www.baeldung.com/scala/traits)
1313
- [Sealed Keyword in Scala](https://www.baeldung.com/scala/sealed-keyword)
1414
- [Pattern Matching in Scala](https://www.baeldung.com/scala/pattern-matching)
15+
- [Using java.lang.class Objects in Scala](https://www.baeldung.com/scala/java-lang-class)

scala-strings/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ This module contains articles about Scala's core features
1212
- [Scala Keyword Matching: A Library-First Guide](https://www.baeldung.com/scala/keyword-matching)
1313
- [Generate Secure Random Passwords in Scala](https://www.baeldung.com/scala/generate-secure-random-passwords)
1414
- [Generate an Acronym for a Given String in Scala](https://www.baeldung.com/scala/string-derive-acronym)
15+
- [Capitalizing Every Word in a Sentence in Scala](https://www.baeldung.com/scala/capitalize-each-word)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.scala.strings.capitalize
2+
3+
object CapitalizeWords {
4+
5+
def capitalizeWords(sentence: String): String = {
6+
sentence.split("\\s+").map(_.capitalize).mkString(" ")
7+
}
8+
9+
def capitalizeTitleCase(sentence: String): String = {
10+
val exclusions = Set("is", "in", "to", "a", "an", "the")
11+
sentence
12+
.split("\\s+")
13+
.zipWithIndex
14+
.map { (word, index) =>
15+
if (index != 0 && exclusions.contains(word.toLowerCase)) word
16+
else word.capitalize
17+
}
18+
.mkString(" ")
19+
}
20+
21+
def capitalizeWordsPreserveSpaces(sentence: String): String = {
22+
sentence.zipWithIndex.map { (char, index) =>
23+
if (index == 0) char.toUpper
24+
else if (sentence.charAt(index - 1).isSpaceChar) char.toUpper
25+
else char
26+
}.mkString
27+
}
28+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.scala.strings.capitalize
2+
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
import org.scalatest.matchers.should.Matchers
5+
import org.scalatest.prop.TableDrivenPropertyChecks
6+
7+
class CapitalizeWordsUnitTest
8+
extends AnyFlatSpec
9+
with Matchers
10+
with TableDrivenPropertyChecks {
11+
12+
val table = Table(
13+
("Input", "Expected"),
14+
("This is scala 3", "This Is Scala 3"),
15+
("hello world", "Hello World"),
16+
("baeldung articles", "Baeldung Articles"),
17+
(" ", ""),
18+
("1000", "1000")
19+
)
20+
it should "capitalize every words of a sentence" in {
21+
forAll(table) { (input, expected) =>
22+
CapitalizeWords.capitalizeWords(input) shouldBe expected
23+
}
24+
}
25+
26+
val tableWithExclusions = Table(
27+
("Input", "Expected"),
28+
("This is scala 3", "This is Scala 3"),
29+
("baeldung articles", "Baeldung Articles"),
30+
(" ", ""),
31+
(
32+
"the quick brown fox jumps over the lazy Dog",
33+
"The Quick Brown Fox Jumps Over the Lazy Dog"
34+
)
35+
)
36+
it should "capitalize every word of a sentence with exclusion" in {
37+
forAll(tableWithExclusions) { (input, expected) =>
38+
CapitalizeWords.capitalizeTitleCase(input) shouldBe expected
39+
}
40+
}
41+
42+
val tablePreservingSpace = Table(
43+
("Input", "Expected"),
44+
("This is scala 3", "This Is Scala 3"),
45+
("hello world", "Hello World"),
46+
("baeldung articles", "Baeldung Articles"),
47+
(" ", " "),
48+
("1000", "1000")
49+
)
50+
it should "capitalize every words of a sentence preserving the spaces" in {
51+
forAll(tablePreservingSpace) { (input, expected) =>
52+
CapitalizeWords.capitalizeWordsPreserveSpaces(input) shouldBe expected
53+
}
54+
}
55+
56+
}

0 commit comments

Comments
 (0)