scala-with-cats icon indicating copy to clipboard operation
scala-with-cats copied to clipboard

Copypaste issue in example 6.2 Apply Syntax

Open voropaevp opened this issue 4 years ago • 2 comments

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

voropaevp avatar Sep 12 '20 16:09 voropaevp

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")
)

jacospain avatar Aug 04 '21 16:08 jacospain

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

Darkest avatar Aug 12 '21 11:08 Darkest