Solutions to Scala with Cats: Chapter 6
April 5, 2023These are my solutions to the exercises of chapter 6 of Scala with Cats.
Table of Contents
Exercise 6.3.1.1: The Product of Lists
The reason product
for List
produces the Cartesian product is because List
forms a Monad
, and product
is implemented in terms of flatMap
. So
Semigroupal[List].product(List(1, 2), List(3, 4))
is the same as:
Which results in the Cartesian product.
Exercise 6.4.0.1: Parallel List
List
does have a Parallel
instance. It zips the lists instead of doing the
Cartesian product. This can be exhibited by the following snippet: