Skip to content

Commit 0bb7837

Browse files
author
Abhijit Sarkar
committed
Upgrade scalafmt in order to get SIP-64 syntax support
1 parent d684f6c commit 0bb7837

13 files changed

+54
-64
lines changed

.scalafmt.conf

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
version = "3.8.3"
1+
version = "3.8.4-RC4"
22
align.preset = more
33
maxColumn = 120
44
runner.dialect = scala3
55
assumeStandardLibraryStripMargin = true
6-
# https://github.com/scalameta/scalameta/issues/4090
7-
project.excludePaths = [
8-
"glob:**/ch04/src/**.scala",
9-
"glob:**/ch06/src/Cat.scala",
10-
"glob:**/ch07/src/*.scala",
11-
"glob:**/ch08/src/*.scala",
12-
"glob:**/ch09/src/*.scala",
13-
"glob:**/ch09/src/*.sc",
14-
]

ch04/src/Cat.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ final case class Cat(name: String, age: Int, color: String)
55
object Cat:
66
given catDisplay: Display[Cat]:
77
def display(cat: Cat): String =
8-
val name = Display.display(cat.name)
9-
val age = Display.display(cat.age)
8+
val name = Display.display(cat.name)
9+
val age = Display.display(cat.age)
1010
val color = Display.display(cat.color)
1111
s"$name is a $age year-old $color cat."

ch04/src/Display.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package ch04
22

33
/*
44
4.5 Exercise: Display Library
5-
*/
5+
*/
66
trait Display[A]:
77
def display(value: A): String
88

9-
109
object Display:
1110
given stringDisplay: Display[String]:
1211
def display(input: String): String = input
@@ -23,4 +22,4 @@ object Display:
2322
object DisplaySyntax:
2423
extension [A](value: A)(using p: Display[A])
2524
def display: String = p.display(value)
26-
def print: Unit = Display.print(value)
25+
def print: Unit = Display.print(value)

ch06/src/Cat.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package ch06
22

33
import cats.{Eq, Show}
4-
import cats.syntax.show.toShow // A.show if Show[A] exists
5-
import cats.syntax.eq.catsSyntaxEq // ===
4+
import cats.syntax.show.toShow // A.show if Show[A] exists
5+
import cats.syntax.eq.catsSyntaxEq // ===
66

77
final case class Cat(name: String, age: Int, color: String)
88

99
object Cat:
1010
/*
1111
6.2.1.1 Exercise: Cat Show
1212
Re-implement the Cat application from Section 4.5.1 using Show instead of Display.
13-
*/
13+
*/
1414
given Show[Cat]:
1515
override def show(cat: Cat): String =
1616
val name = cat.name.show
@@ -21,9 +21,9 @@ object Cat:
2121
/*
2222
6.3.4.1 Exercise: Equality, Liberty, and Felinity
2323
Implement an instance of Eq for our running Cat example.
24-
*/
24+
*/
2525
given Eq[Cat]:
2626
override def eqv(x: Cat, y: Cat): Boolean =
2727
(x.name === y.name) &&
2828
(x.age === y.age) &&
29-
(x.color === y.color)
29+
(x.color === y.color)

ch07/src/Lib.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package ch07
22

33
/*
4-
We can use Semigroups and Monoids by importing two things: the type classes themselves,
4+
We can use Semigroups and Monoids by importing two things: the type classes themselves,
55
and the semigroup syntax to give us the |+| operator.
6-
*/
7-
import cats.syntax.semigroup.catsSyntaxSemigroup // A |+| A if Semigroup[A] exists
6+
*/
7+
import cats.syntax.semigroup.catsSyntaxSemigroup // A |+| A if Semigroup[A] exists
88

99
object Lib:
1010

@@ -47,4 +47,4 @@ object Lib:
4747
o1.quantity + o2.quantity
4848
)
4949

50-
def empty = Order(0, 0)
50+
def empty = Order(0, 0)

ch07/src/Monoid.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Monoid[A] extends Semigroup[A]:
44
def empty: A
55

66
object Monoid:
7-
def apply[A : Monoid as m]: Monoid[A] = m
7+
def apply[A: Monoid as m]: Monoid[A] = m
88

99
/*
1010
7.2.0.1 Exercise: The Truth About Monoids
@@ -33,12 +33,12 @@ object Monoid:
3333
/*
3434
7.2.0.2 Exercise: All Set for Monoids
3535
What monoids and semigroups are there for sets?
36-
*/
36+
*/
3737
given setUnionMonoid: [A] => Monoid[Set[A]]:
3838
def combine(a: Set[A], b: Set[A]) = a.union(b)
3939
def empty = Set.empty[A]
4040

4141
given symDiffMonoid: [A] => Monoid[Set[A]]:
4242
def combine(a: Set[A], b: Set[A]): Set[A] =
4343
(a.diff(b)).union(b.diff(a))
44-
def empty: Set[A] = Set.empty
44+
def empty: Set[A] = Set.empty

ch08/src/Codec.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ trait Codec[A]:
1616
override def decode(value: String): B =
1717
dec(self.decode(value))
1818

19-
def encode[A : Codec as c](value: A): String =
19+
def encode[A: Codec as c](value: A): String =
2020
c.encode(value)
2121

22-
def decode[A : Codec as c](value: String): A =
22+
def decode[A: Codec as c](value: String): A =
2323
c.decode(value)
2424

2525
object Codec:
@@ -37,5 +37,5 @@ object Codec:
3737
stringCodec.imap(_.toDouble, _.toString)
3838

3939
// Implement a Codec for the Box type.
40-
given boxCodec: [A : Codec as c] => Codec[Box[A]] =
40+
given boxCodec: [A: Codec as c] => Codec[Box[A]] =
4141
c.imap[Box[A]](Box(_), _.value)

ch08/src/Display.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Display:
3636
// Given a Display[A], and a Box[A], we can create
3737
// Display[Box[A]] by the reverse mapping Box[A] => A.
3838
// The forward mapping would be A => Box[A].
39-
39+
4040
// Parameterized typeclass with named context bound.
41-
given [A : Display as d] => Display[Box[A]] =
41+
given [A: Display as d] => Display[Box[A]] =
4242
d.contramap[Box[A]](_.value)

ch08/src/Tree.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ object Tree:
1010
import Tree.*
1111

1212
/* 8.5.4 Exercise: Branching out with Functors
13-
Write a Functor for the following binary tree data type.
13+
Write a Functor for the following binary tree data type.
1414
Verify that the code works as expected on instances of Branch and Leaf.
15-
*/
15+
*/
1616
given Functor[Tree]:
1717
override def map[A, B](fa: Tree[A])(f: A => B): Tree[B] =
1818
fa match
1919
case Branch(l, r) => Branch(map(l)(f), map(r)(f))
2020
case Leaf(value) => Leaf(f(value))
2121

22-
// The compiler can find a Functor instance for Tree but not for Branch or Leaf
22+
// The compiler can find a Functor instance for Tree but not for Branch or Leaf
2323
// (Functor is invariant in F). Let's add some smart constructors to compensate.
2424
def branch[A](left: Tree[A], right: Tree[A]): Tree[A] =
2525
Branch(left, right)
2626

2727
def leaf[A](value: A): Tree[A] =
28-
Leaf(value)
28+
Leaf(value)

ch09/src/Lib.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package ch09
22

33
import cats.{Eval, MonadError}
44
import cats.data.{Reader, Writer, State}
5-
import cats.syntax.applicative.catsSyntaxApplicativeId // pure
6-
import cats.syntax.writer.catsSyntaxWriterId // tell
7-
import cats.syntax.apply.catsSyntaxApplyOps // *>
5+
import cats.syntax.applicative.catsSyntaxApplicativeId // pure
6+
import cats.syntax.writer.catsSyntaxWriterId // tell
7+
import cats.syntax.apply.catsSyntaxApplyOps // *>
88

99
object Lib:
1010
/*

ch09/src/Monad.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ trait Monad[F[_]]:
2525
def pure[A](a: A): Id[A] = a
2626

2727
def flatMap[A, B](value: Id[A])(f: A => Id[B]): Id[B] =
28-
f(value)
28+
f(value)

ch09/src/Tree.scala

+21-21
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ package ch09
1212
despite the fact that we haven’t directly implemented flatMap or map on Tree.
1313
1414
Don't feel you have to make tailRecM tail-recursive. Doing so is quite difficult.
15-
*/
16-
enum Tree[A]:
17-
case Leaf(value: A)
18-
case Branch(left: Tree[A], right: Tree[A])
15+
*/
16+
enum Tree[A]:
17+
case Leaf(value: A)
18+
case Branch(left: Tree[A], right: Tree[A])
1919

20-
object Tree:
21-
import Tree.*
20+
object Tree:
21+
import Tree.*
2222

23-
given cats.Monad[Tree]:
24-
override def pure[A](x: A): Tree[A] =
25-
Leaf(x)
23+
given cats.Monad[Tree]:
24+
override def pure[A](x: A): Tree[A] =
25+
Leaf(x)
2626

27-
override def flatMap[A, B](t: Tree[A])(f: A => Tree[B]): Tree[B] =
27+
override def flatMap[A, B](t: Tree[A])(f: A => Tree[B]): Tree[B] =
2828
t match
29-
case Leaf(x) => f(x)
30-
case Branch(l, r) => Branch(flatMap(l)(f), flatMap(r)(f))
29+
case Leaf(x) => f(x)
30+
case Branch(l, r) => Branch(flatMap(l)(f), flatMap(r)(f))
3131

32-
// Not stack-safe!
33-
override def tailRecM[A, B](a: A)(f: A => Tree[Either[A, B]]): Tree[B] =
32+
// Not stack-safe!
33+
override def tailRecM[A, B](a: A)(f: A => Tree[Either[A, B]]): Tree[B] =
3434
flatMap(f(a)):
35-
case Left(value) => tailRecM(value)(f)
36-
case Right(value) => Leaf(value)
35+
case Left(value) => tailRecM(value)(f)
36+
case Right(value) => Leaf(value)
3737

38-
// Smart constructors to help the compiler.
39-
def branch[A](left: Tree[A], right: Tree[A]): Tree[A] =
40-
Branch(left, right)
38+
// Smart constructors to help the compiler.
39+
def branch[A](left: Tree[A], right: Tree[A]): Tree[A] =
40+
Branch(left, right)
4141

42-
def leaf[A](value: A): Tree[A] =
43-
Leaf(value)
42+
def leaf[A](value: A): Tree[A] =
43+
Leaf(value)

ch09/src/ch09.worksheet.sc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cats.{Id, Eval, MonadError}
22
import cats.data.{Reader, Writer, State}
3-
import cats.syntax.functor.toFunctorOps // map
4-
import cats.syntax.flatMap.toFlatMapOps // flatMap
5-
import cats.syntax.applicative.catsSyntaxApplicativeId // pure
3+
import cats.syntax.functor.toFunctorOps // map
4+
import cats.syntax.flatMap.toFlatMapOps // flatMap
5+
import cats.syntax.applicative.catsSyntaxApplicativeId // pure
66
import cats.syntax.writer.catsSyntaxWriterId // tell
77

88
// 9.3 The Identity Monad

0 commit comments

Comments
 (0)