Skip to content

Commit cae069a

Browse files
authored
Merge pull request #557 from yadavan88/scalafmt-styling
Scalafmt on the entire project
2 parents 5cf1dc8 + 7a76062 commit cae069a

File tree

381 files changed

+4328
-3032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

381 files changed

+4328
-3032
lines changed

.scalafmt.conf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
version = 3.5.9
2-
runner.dialect = scala3
1+
version = 3.7.1
2+
runner.dialect = scala213
3+
fileOverride {
4+
"glob:**/scala3-*/**" {
5+
runner.dialect = scala3
6+
}
7+
}
38
continuationIndent.defnSite = 2
49
continuationIndent.ctorSite = 2
510
continuationIndent.extendSite = 2

cats-effects/src/main/scala/com/baeldung/scala/catseffects/LazyIO.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package com.baeldung.scala.catseffects
22

33
case class LazyIO[A](runEffect: () => A) {
44
def map[B](fn: A => B): LazyIO[B] = LazyIO.io(fn(runEffect()))
5-
6-
def flatMap[B](fn: A => LazyIO[B]): LazyIO[B] = LazyIO.io(fn(runEffect()).runEffect())
5+
6+
def flatMap[B](fn: A => LazyIO[B]): LazyIO[B] =
7+
LazyIO.io(fn(runEffect()).runEffect())
78
}
89

910
object LazyIO {

cats-effects/src/main/scala/com/baeldung/scala/catseffects/MissileLaucher.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import cats.effect.{ExitCode, IO, IOApp}
44

55
object MissileLaucher extends IOApp {
66
def putStr(str: String): IO[Unit] = IO.delay(println(str))
7-
7+
88
val launch: IO[Unit] = for {
99
_ <- putStr("Lauch missiles")
1010
_ <- putStr("Lauch missiles")
1111
} yield ()
12-
13-
override def run(args: List[String]): IO[ExitCode] = launch.as(ExitCode.Success)
12+
13+
override def run(args: List[String]): IO[ExitCode] =
14+
launch.as(ExitCode.Success)
1415
}

cats-effects/src/main/scala/com/baeldung/scala/catseffects/NotParallelApp.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import com.baeldung.scala.catseffects.Utils.ShowThread
77
object NotParallelApp extends IOApp {
88
val tasks: List[IO[Int]] = (1 to 10).map(IO.pure).map(_.showThread).toList
99

10-
val incremented: IO[List[Int]] = tasks.traverse {
11-
ioi => for (i <- ioi) yield i + 1
10+
val incremented: IO[List[Int]] = tasks.traverse { ioi =>
11+
for (i <- ioi) yield i + 1
1212
}
13-
13+
1414
val parallelOrNot: IO[List[Int]] = incremented.showThread
15-
16-
override def run(args: List[String]): IO[ExitCode] = parallelOrNot.as(ExitCode.Success)
17-
15+
16+
override def run(args: List[String]): IO[ExitCode] =
17+
parallelOrNot.as(ExitCode.Success)
18+
1819
}

cats-effects/src/main/scala/com/baeldung/scala/catseffects/ParallelApp.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import com.baeldung.scala.catseffects.Utils.ShowThread
77
object ParallelApp extends IOApp {
88
val tasks: List[IO[Int]] = (1 to 10).map(IO.pure).map(_.showThread).toList
99

10-
val incremented: IO[List[Int]] = tasks.parTraverse {
11-
ioi => for (i <- ioi) yield i + 1
10+
val incremented: IO[List[Int]] = tasks.parTraverse { ioi =>
11+
for (i <- ioi) yield i + 1
1212
}
1313

1414
val parallelOrNot: IO[List[Int]] = incremented.showThread
1515

16-
override def run(args: List[String]): IO[ExitCode] = parallelOrNot.as(ExitCode.Success)
16+
override def run(args: List[String]): IO[ExitCode] =
17+
parallelOrNot.as(ExitCode.Success)
1718
}

cats-effects/src/main/scala/com/baeldung/scala/catseffects/SequenceApp.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ object SequenceApp extends IOApp {
88

99
val tasks: List[IO[Int]] = (1 to 1000).map(IO.pure).toList
1010
val sequenceAllTasks: IO[List[Int]] = tasks.sequence
11-
val printTaskSequence: IO[Unit] = sequenceAllTasks.map(_.mkString(", ")).flatMap(putStr)
12-
13-
override def run(args: List[String]): IO[ExitCode] = sequenceAllTasks.as(ExitCode.Success)
11+
val printTaskSequence: IO[Unit] =
12+
sequenceAllTasks.map(_.mkString(", ")).flatMap(putStr)
13+
14+
override def run(args: List[String]): IO[ExitCode] =
15+
sequenceAllTasks.as(ExitCode.Success)
1416
}

cats-effects/src/main/scala/com/baeldung/scala/catseffects/Substitution.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ object Substitution {
1111
}
1212

1313
def effectfulWithFuture(): Unit = {
14-
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
15-
Future(println("Launch missiles")).map(_ => Future(println("Launch missiles")))
14+
implicit val ec: ExecutionContextExecutor = ExecutionContext.global
15+
Future(println("Launch missiles")).map(_ =>
16+
Future(println("Launch missiles"))
17+
)
1618
}
1719

1820
def effectfulWithFutureRefactored(): Unit = {

cats-effects/src/main/scala/com/baeldung/scala/catseffects/TraverseApp.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ object TraverseApp extends IOApp {
99
val tasks: List[Int] = (1 to 1000).toList
1010
def taskExecutor(i: Int): String = s"Executing task $i"
1111
val runAllTasks: IO[List[Unit]] = tasks.traverse(i => putStr(taskExecutor(i)))
12-
13-
override def run(args: List[String]): IO[ExitCode] = runAllTasks.as(ExitCode.Success)
12+
13+
override def run(args: List[String]): IO[ExitCode] =
14+
runAllTasks.as(ExitCode.Success)
1415
}

cats-effects/src/main/scala/com/baeldung/scala/catseffects/Utils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cats.effect.IO
55
object Utils {
66
implicit class ShowThread[T](io: IO[T]) {
77
def showThread: IO[T] = for {
8-
thunk <- io
8+
thunk <- io
99
thread = Thread.currentThread.getName
1010
_ = println(s"[$thread] $thunk")
1111
} yield thunk

cats-effects/src/main/scala/com/baeldung/scala/differences/Differences.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ object Differences extends IOApp.Simple {
1111

1212
val delayedDurationIO = io.delayBy(3.seconds)
1313

14-
//This will fail with Stackoverflow Exception
14+
// This will fail with Stackoverflow Exception
1515
def neverEnding(io: IO[Int]): IO[Unit] = { io *> neverEnding(io) }
1616

17-
//This will run forever without any StackOverflowException
17+
// This will run forever without any StackOverflowException
1818
def neverEndingV2(io: IO[Int]): IO[Unit] = {
1919
io *> IO.defer(neverEndingV2(io))
2020
}

cats-effects/src/main/scala/com/baeldung/scala/differences/FlatEvalDiff.scala

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,37 @@ import cats.effect.{IO, IOApp, Resource}
44

55
object FlatEvalDiff extends IOApp.Simple {
66

7-
val strIO = IO("This is a string IO")
8-
7+
val strIO = IO("This is a string IO")
8+
99
def countLetters(str: String): IO[Int] = IO(str.length())
1010

1111
val countIO: IO[Int] = strIO.flatMap(s => countLetters(s))
1212

1313
def countLettersWithPrint(str: String): IO[Unit] = IO {
14-
println("String length is "+str.length())
14+
println("String length is " + str.length())
1515
}
1616
val flatTapIO: IO[String] = strIO.flatTap(countLettersWithPrint)
1717

18-
val flatTapIO_V2: IO[String] = strIO.map{r =>
18+
val flatTapIO_V2: IO[String] = strIO.map { r =>
1919
countLettersWithPrint(r)
2020
r
2121
}
2222

2323
case class SimpleConnection(url: String)
2424
case class ComplexConnection(url: String)
2525
def acquireResource(): IO[SimpleConnection] = {
26-
IO.println("Opening Simple Connection") >> IO(SimpleConnection("localhost:8000"))
26+
IO.println("Opening Simple Connection") >> IO(
27+
SimpleConnection("localhost:8000")
28+
)
2729
}
2830
def releaseResource(con: SimpleConnection): IO[Unit] = {
29-
IO.println("Closing Simple Connection: "+con.url)
31+
IO.println("Closing Simple Connection: " + con.url)
3032
}
31-
32-
val resource: Resource[IO,SimpleConnection] = Resource.make(acquireResource)(releaseResource)
33-
val simpleResourceData: IO[Unit] = resource.use(simpleConn => IO.println("Result using Simple Resource"))
33+
34+
val resource: Resource[IO, SimpleConnection] =
35+
Resource.make(acquireResource)(releaseResource)
36+
val simpleResourceData: IO[Unit] =
37+
resource.use(simpleConn => IO.println("Result using Simple Resource"))
3438

3539
def transformConnection(con: SimpleConnection) = {
3640
IO {
@@ -39,13 +43,18 @@ object FlatEvalDiff extends IOApp.Simple {
3943
}
4044
}
4145

42-
val modifiedResource: Resource[IO,ComplexConnection] = resource.evalMap(con => transformConnection(con))
43-
val tappedResource: Resource[IO,SimpleConnection] = resource.evalTap(con => transformConnection(con))
44-
45-
val evalTapRes: IO[Unit] = tappedResource.use(simple => IO.println("Using simple connection from evalTap to execute.."))
46-
val evalMapRes: IO[Unit] = modifiedResource.use(complex => IO.println("Using complex connection from evalMap to execute.."))
46+
val modifiedResource: Resource[IO, ComplexConnection] =
47+
resource.evalMap(con => transformConnection(con))
48+
val tappedResource: Resource[IO, SimpleConnection] =
49+
resource.evalTap(con => transformConnection(con))
4750

51+
val evalTapRes: IO[Unit] = tappedResource.use(simple =>
52+
IO.println("Using simple connection from evalTap to execute..")
53+
)
54+
val evalMapRes: IO[Unit] = modifiedResource.use(complex =>
55+
IO.println("Using complex connection from evalMap to execute..")
56+
)
4857

4958
override def run: IO[Unit] = evalTapRes
5059

51-
}
60+
}

cats-effects/src/main/scala/com/baeldung/scala/fibers/Fibers.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ object Fibers extends IOApp.Simple {
3030

3131
val outcome: IO[String] = fibCancel.flatMap {
3232
case Outcome.Succeeded(fa) => IO("fiber executed successfully").printIO
33-
case Outcome.Errored(e) => IO("error occurred during fiber execution").printIO
34-
case Outcome.Canceled() => IO("fiber was canceled!").printIO
33+
case Outcome.Errored(e) =>
34+
IO("error occurred during fiber execution").printIO
35+
case Outcome.Canceled() => IO("fiber was canceled!").printIO
3536
}
3637

3738
val ioWithCancelationHook =
@@ -67,7 +68,10 @@ object Fibers extends IOApp.Simple {
6768

6869
val ioWithTimeout: IO[String] = participant1.timeout(400.millis)
6970

70-
val ioWithFallback = participant1.timeoutTo(400.millis, IO("Fallback IO executed after timeout").printIO)
71+
val ioWithFallback = participant1.timeoutTo(
72+
400.millis,
73+
IO("Fallback IO executed after timeout").printIO
74+
)
7175

7276
override def run: IO[Unit] = ioWithFallback.void
7377
}

doobie/src/main/scala/com/baeldung/scala/doobie/DoobieFragments.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ object DoobieFragments extends IOApp.Simple {
1616

1717
import doobie.Fragments._
1818
val optionalCityNameParam: Option[String] = Some("%Pol%")
19-
val optionalCityNameFragment: Option[Fragment] = optionalCityNameParam.map(name => fr"name like $name")
19+
val optionalCityNameFragment: Option[Fragment] =
20+
optionalCityNameParam.map(name => fr"name like $name")
2021
val limitFragment = fr"limit 5"
2122

2223
(for {
23-
selectedCities <- (fr"select name from city" ++ whereAndOpt(optionalCityNameFragment)).query[String].to[List]
24-
selectedLimitedCities <- (fr"select name from city" ++ limitFragment).query[String].to[List]
25-
} yield (selectedCities, selectedLimitedCities)).transact(transactor).map { tuple =>
26-
println(s"fragment results: $tuple")
24+
selectedCities <- (fr"select name from city" ++ whereAndOpt(
25+
optionalCityNameFragment
26+
)).query[String].to[List]
27+
selectedLimitedCities <- (fr"select name from city" ++ limitFragment)
28+
.query[String]
29+
.to[List]
30+
} yield (selectedCities, selectedLimitedCities)).transact(transactor).map {
31+
tuple =>
32+
println(s"fragment results: $tuple")
2733
}
2834
}
2935
}
30-

doobie/src/main/scala/com/baeldung/scala/doobie/DoobieQuickStart.scala

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import doobie.implicits._
55
import doobie.{ConnectionIO, Transactor}
66

77
// Equivalent to world db city table
8-
case class City(id: Long, name: String, countryCode: String, district: String, population: Int)
8+
case class City(
9+
id: Long,
10+
name: String,
11+
countryCode: String,
12+
district: String,
13+
population: Int
14+
)
915

1016
object DoobieQuickStart extends IOApp.Simple {
1117

@@ -18,26 +24,29 @@ object DoobieQuickStart extends IOApp.Simple {
1824
)
1925

2026
val operations: ConnectionIO[Unit] = for {
21-
someCities <- sql"select id, name, country_code, district, population from city limit 5"
22-
.query[City]
23-
.to[List]
27+
someCities <-
28+
sql"select id, name, country_code, district, population from city limit 5"
29+
.query[City]
30+
.to[List]
2431
_ = println(s"Selected some cities: $someCities")
2532
baeldungCity = City(5000, "Baeldung", "NLD", "Baeldungland", 1337)
26-
insertedId <- sql"insert into city (id, name, country_code, district, population) values (${baeldungCity.id}, ${baeldungCity.name}, ${baeldungCity.countryCode}, ${baeldungCity.district}, ${baeldungCity.population})"
27-
.update
28-
.withUniqueGeneratedKeys[Int]("id")
33+
insertedId <-
34+
sql"insert into city (id, name, country_code, district, population) values (${baeldungCity.id}, ${baeldungCity.name}, ${baeldungCity.countryCode}, ${baeldungCity.district}, ${baeldungCity.population})".update
35+
.withUniqueGeneratedKeys[Int]("id")
2936
_ = println(s"Inserted baeldung city: $insertedId")
30-
selectedCity <- sql"select id, name, country_code, district, population from city where id = $insertedId"
31-
.query[City]
32-
.unique
37+
selectedCity <-
38+
sql"select id, name, country_code, district, population from city where id = $insertedId"
39+
.query[City]
40+
.unique
3341
_ = println(s"Selected baeldung city: $selectedCity")
34-
updatedName <- sql"update city set name = 'DungBael' where id = 5000"
35-
.update
36-
.withUniqueGeneratedKeys[String]("name")
37-
_ = println(s"Updated baeldung city: ${baeldungCity.name} -> $updatedName")
38-
deletedRows <- sql"delete from city where id = ${baeldungCity.id}"
39-
.update
40-
.run
42+
updatedName <-
43+
sql"update city set name = 'DungBael' where id = 5000".update
44+
.withUniqueGeneratedKeys[String]("name")
45+
_ = println(
46+
s"Updated baeldung city: ${baeldungCity.name} -> $updatedName"
47+
)
48+
deletedRows <-
49+
sql"delete from city where id = ${baeldungCity.id}".update.run
4150
_ = println(s"Deleted baeldung city: $deletedRows")
4251
} yield ()
4352

reflection/src/main/scala/com/baeldung/reflection/Person.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ case class Person(name: String, age: Int) extends PersonInterface {
88
| age: $age
99
|}
1010
|""".stripMargin
11-
11+
1212
private val password = "123"
1313
}

reflection/src/test/scala/com/baeldung/reflection/JavaReflectionTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ class JavaReflectionTest {
77
def invoke_method_dynamically(): Unit = {
88
val person = Person("John", 20)
99
val result = classOf[Person].getDeclaredMethod("prettyPrint").invoke(person)
10-
assert(result ==
11-
s"""
10+
assert(
11+
result ==
12+
s"""
1213
|Person {
1314
| name: "John",
1415
| age: 20

0 commit comments

Comments
 (0)