scalawithcats / scala-with-cats

Source code for Scala with Cats
http://underscore.io/books/scala-with-cats
390 stars 129 forks source link

Copypaste issue in example 6.2 Apply Syntax #196

Open voropaevp opened 3 years ago

voropaevp commented 3 years ago

In chapter 6.2 Apply Syntax

Book version:


(Option(1), Option(2), Option(3)).mapN(add)
// error: ':' expected but '(' found.
//   Option("Garfield"),
//         ^
// error: identifier expected but '}' found.

(Option("cats"), Option(true)).mapN(add)
// error: ':' expected but '(' found.
//   Option("Garfield"),
//         ^
// error: identifier expected but '}' found.

Correct version:

scala> (Option(1), Option(2), Option(3)).mapN(add)
                                              ^
       error: type mismatch;
        found   : (Int, Int) => Int
        required: (Int, Int, Int) => ?
(Int, Int) => Int <: (Int, Int, Int) => ??
false

scala> (Option("cats"), Option(true)).mapN(add)
                                           ^
       error: type mismatch;
        found   : (Int, Int) => Int
        required: (String, Boolean) => ?
(Int, Int) => Int <: (String, Boolean) => ??
false
jacospain commented 2 years ago

This remains an issue. You can get the compiler output from the book if you run the example code from the chapter with no newline between this case class definition and the immediately following expression:

final case class Cat(name: String, born: Int, color: String)
(
Option("Garfield"),
Option(1978),
Option("Orange & black")
)
Darkest commented 2 years ago

This remains an issue. You can get the compiler output from the book if you run the example code from the chapter with no newline between this case class definition and the immediately following expression:

final case class Cat(name: String, born: Int, color: String)
(
Option("Garfield"),
Option(1978),
Option("Orange & black")
)

Nevertheless i think the compiler output in the book should be fixed