Suffering from nothing

How does A

Nothing

the process work?

def seq2map[A](src: Seq[A]): Map[A, A] = {
    def pair = for {
        f <- src.headOption
        s <- src.headOption
    } yield (f, s)
    Stream continually pair takeWhile(_ isDefined) toMap
}

      

error: the type expression Map[Nothing, Nothing]

does not match the expected typeMap[A, A]

Thank!

+3


source to share


1 answer


I get

<console>:12: error: Cannot prove that Option[(A, A)] <:< (T, U).
           Stream continually pair takeWhile(_ isDefined) toMap
                                                          ^

      

because

scala> val src = (1 to 10).toSeq
src: scala.collection.immutable.Range = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

scala>     def pair = for {
     |         f <- src.headOption
     |         s <- src.headOption
     |     } yield (f, s)
pair: Option[(Int, Int)]

      



not a couple, but an option.

scala> (Stream continually pair takeWhile (_.isDefined)).flatten
res0: scala.collection.immutable.Stream[(Int, Int)] = Stream((1,1), ?)

      

- steam flow.

Waiting for the start of the game.

+4


source







All Articles