Skip to content

Commit 685e604

Browse files
author
Abhijit Sarkar
committed
Complete ch13
1 parent 0bb7837 commit 685e604

File tree

13 files changed

+257
-9
lines changed

13 files changed

+257
-9
lines changed

.mill-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.12.4
1+
0.12.5

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version = "3.8.4-RC4"
22
align.preset = more
3-
maxColumn = 120
3+
maxColumn = 100
44
runner.dialect = scala3
55
assumeStandardLibraryStripMargin = true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The older code is available in branches.
2020
10. [Monad Transformers](ch10)
2121
11. [Semigroupal and Applicative](ch11)
2222
12. [Foldable and Traverse](ch12)
23+
13. [Indexed Types](ch13)
2324

2425
## Running tests
2526
```

ch05/src/ExpressionT.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ enum ExpressionT:
1717
case Loop(expr: ExpressionT, k: Continuation)
1818
case Done(result: Double)
1919

20-
def loop2(left: ExpressionT, right: ExpressionT, cont: Continuation, op: (Double, Double) => Double): Call =
20+
def loop2(
21+
left: ExpressionT,
22+
right: ExpressionT,
23+
cont: Continuation,
24+
op: (Double, Double) => Double
25+
): Call =
2126
Call.Loop(
2227
left,
2328
l => Call.Loop(right, r => Call.Continue(op(l, r), cont))

ch05/test/src/ExpressionCSpec.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import org.scalatest.matchers.should.Matchers.shouldBe
66
class ExpressionCSpec extends AnyFunSpec:
77
describe("ExpressionC"):
88
it("eval"):
9-
val fortyTwo = ((ExpressionC(15.0) + ExpressionC(5.0)) * ExpressionC(2.0) + ExpressionC(2.0)) / ExpressionC(1.0)
9+
val fortyTwo = ((ExpressionC(15.0) + ExpressionC(5.0)) * ExpressionC(2.0) + ExpressionC(
10+
2.0
11+
)) / ExpressionC(1.0)
1012
fortyTwo.eval shouldBe 42.0d

ch05/test/src/ExpressionSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import org.scalatest.matchers.should.Matchers.shouldBe
66
class ExpressionSpec extends AnyFunSpec:
77
describe("Expression"):
88
it("eval"):
9-
val fortyTwo = ((Expression(15.0) + Expression(5.0)) * Expression(2.0) + Expression(2.0)) / Expression(1.0)
9+
val fortyTwo =
10+
((Expression(15.0) + Expression(5.0)) * Expression(2.0) + Expression(2.0)) / Expression(1.0)
1011
fortyTwo.eval shouldBe 42.0d

ch05/test/src/ExpressionTSpec.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import org.scalatest.matchers.should.Matchers.shouldBe
66
class ExpressionTSpec extends AnyFunSpec:
77
describe("ExpressionT"):
88
it("eval"):
9-
val fortyTwo = ((ExpressionT(15.0) + ExpressionT(5.0)) * ExpressionT(2.0) + ExpressionT(2.0)) / ExpressionT(1.0)
9+
val fortyTwo = ((ExpressionT(15.0) + ExpressionT(5.0)) * ExpressionT(2.0) + ExpressionT(
10+
2.0
11+
)) / ExpressionT(1.0)
1012
fortyTwo.eval shouldBe 42.0d

ch06/test/src/CatSpec.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import cats.syntax.eq.catsSyntaxEq
88
class CatSpec extends AnyFunSpec:
99
describe("Cat"):
1010
it("Show"):
11-
Cat("Garfield", 41, "ginger and black").show shouldBe "Garfield is a 41 year-old ginger and black cat."
11+
Cat(
12+
"Garfield",
13+
41,
14+
"ginger and black"
15+
).show shouldBe "Garfield is a 41 year-old ginger and black cat."
1216

1317
it("Eq"):
1418
val cat1 = Cat("Garfield", 38, "orange and black")

ch08/src/ch08.worksheet.sc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ val showString = Show[String]
3838
// trait Contravariant[F[_]]:
3939
// def contramap[A, B](fa: F[A])(f: B => A): F[B]
4040

41-
val showSymbol: Show[Symbol] = Contravariant[Show].contramap(showString)((sym: Symbol) => s"'${sym.name}")
41+
val showSymbol: Show[Symbol] =
42+
Contravariant[Show].contramap(showString)((sym: Symbol) => s"'${sym.name}")
4243

4344
showSymbol.show(Symbol("dave"))
4445

ch09/src/Lib.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ object Lib:
1616

1717
// def validateAdult[F[_] : ([G[_]] =>> MonadError[G, Throwable]) as me](age: Int): F[Int] =
1818
def validateAdult[F[_]](age: Int)(using me: MonadError[F, Throwable]): F[Int] =
19-
me.ensure(me.pure(age))(IllegalArgumentException("Age must be greater than or equal to 18"))(_ >= 18)
19+
me.ensure(me.pure(age))(IllegalArgumentException("Age must be greater than or equal to 18"))(
20+
_ >= 18
21+
)
2022

2123
/*
2224
9.6.5 Exercise: Safer Folding using Eval

0 commit comments

Comments
 (0)